source: liacs/cvp/java/report/report.tex@ 158

Last change on this file since 158 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 6.2 KB
Line 
1\documentclass[a4paper,12pt]{article}
2\usepackage{hyperref}
3\usepackage{a4wide}
4%\usepackage{indentfirst}
5\usepackage[english]{babel}
6\usepackage{graphics}
7%\usepackage[pdftex]{graphicx}
8\usepackage{latexsym}
9\usepackage{fancyhdr}
10\usepackage{fancyvrb}
11
12\parindent=0cm
13
14\pagestyle{fancyplain}
15\newcommand{\tstamp}{\today}
16\newcommand{\id}{$ $Id: report.tex 195 2007-05-30 01:04:25Z rick $ $}
17\lfoot[\fancyplain{\tstamp}{\tstamp}] {\fancyplain{\tstamp}{\tstamp}}
18\cfoot[\fancyplain{\id}{\id}] {\fancyplain{\id}{\id}}
19\rfoot[\fancyplain{\thepage}{\thepage}] {\fancyplain{\thepage}{\thepage}}
20
21
22\title{ Concepts of programming languages \\
23\large{Assignment 1 - Java}}
24\author{Rick van der Zwet\\
25 \texttt{<hvdzwet@liacs.nl>}\\
26 \\
27 LIACS\\
28 Leiden Universiteit\\
29 Niels Bohrweg 1\\
30 2333 CA Leiden\\
31 The Netherlands}
32\date{\today}
33\begin{document}
34\maketitle
35\section{Introduction}
36Analyse on Java program Write two Java programs to get some experience
37implementing concurrent programs in Java.
38
39\section{Analyse Eyes.java}
40Compiling and execution of the program is pretty staight forward
41\begin{verbatim}
42$ javac Eyes.class Eyes.java
43\end{verbatim}
44A detailed explanation of the program code is found in the Appendix -
45Ogen.java \ref{file:Ogen.java}
46
47\section{The Readers/Writer Problem}
48\subsection{Problem}
49\label{rwproblem}
50Two kind processes -readers and writers- share a database. Writers
51execute transactions than update the database; reader transactions
52access the database without modifying it. The database is assumed
53initially to be in a consistend state (i.e one in which relations
54between data are meaningfull). Each transaction, if executed in
55isolation, transforms the database from one consistent state to another.
56To preclude interference between transactions, a writer process must
57have exclusive access to the database. Assuming no writer is accessing
58the database, any number of readers my concurrently execute
59transactions.
60\\
61To tackle this problem we first have to indentify the main states and
62summerize the conditions:
63\begin{enumerate}
64\item No processes is reading/writing the database \\
65Both new read/write processes are allowed to start right away
66\item X processes are reading the database \\
67A new read process is allowed to start right away, a write process needs to
68wait
69\item 1 process is writing the database \\
70Both new read/write processes need to wait
71\end{enumerate}
72
73\subsection{Implementation}
74\label{rw-implentation}
75To implement this problem we keep track how many processes are reading
76the database by using an counter (called Readers), which is incremented
77when an reader starts reading and decremented when done. Writing to the
78datebase will be locked by a flag (called WriteLocked) stating we are
79busy and released when done.
80\\\\
81When a reader process tries to access the database, it will check
82whether the WriteLocked is set free and then increment the Writers, and
83decrement the Writers when done else it will wait
84\\\\
85When a writer process tries to access the database, it will check wether
86the WriteLocked is set free, else it will wait. If the WriteLocked is
87set free and there are no Readers (e.g Readers = 0), it will lock it
88WriteLocked and release when done.
89\\\\
90The java implemetation is found at first/Database.java~\ref{file:Database.java}
91
92\subsection{Test Suite}
93\label{rw-test-suite}
94In order to test this implemtation a test program is created. In short
95it will create X number of readers and writers using threads to make
96them recurrent and have them all access the database
97\\\\
98The java implemetation is found at RWProblem.java~\ref{file:RWProblem.java}
99
100
101\section{The Readers/Writer Problem enhanced}
102\subsection{Problem}
103Implement the Readers/Writers problem (described at~\ref{rwproblem})
104giving priority to the writers: i.e. if a writer wants to enter the
105database but has to wait then no reader may enter, and of course the
106writer still has to wait for current readers in the database to be
107finished
108\\\\
109The main states defined in~\ref{rwproblem} still exists, but the
110state 2 is slightly changed
111\begin{enumerate}
112\item No processes is reading/writing the database \\
113Both new read/write processes are allowed to start right away
114\item X processes are reading the database \\
115A new read process is allowed to start if no writer process is waiting,
116a write process needs to wait
117\item 1 process is writing the database \\
118Both new read/write processes need to wait
119\end{enumerate}
120
121\subsection{Implementation}
122As the actions are slightly changed, the implementation needs to be
123changed a slight little bit as well from the implementation at~
124\ref{rw-implentation}. The flag WriterWaiting will indentify wether a
125Writer is waiting. A Reader which tries to access the database will now
126check wheter both WriteLocked and WriterWaiting are false before reading
127is done.
128A Writer which try to access the database and find the database locked
129by WriteLocked will now set WriterWaiting and start waiting, when a
130Writer find WriteLocked to be false it will start running (setting
131WriteLocked to be true) and set WriterWaiting to be false.
132\\\\
133Using this implementation there is only one caveat -which only occurs
134when the stack grow that big that not all processes database attemps
135are checked during the time of one write- . Take a look at the following
136stack order: W(rite), R(ead), R, R, R, W, R, R. and assume the current state
137is 1 (no-one reading/writing). Process 1 will set the WriteWaiting flag
138to be false, if the write of Process completed, before the next Write is
139checked (and the flag WriteWaiting is set again). The read processes are
140allowed to start even there is a Write process waiting in the queue
141\\\\
142The java implemetation is found at second/Database.java~
143\ref{file:secondDatabase.java}
144
145\subsection{Test Suite}
146Used the same test tool as defined in~\ref{rw-test-suite}
147
148\section{Appendix}
149
150\subsection{Ogen.java}
151\label{file:Ogen.java}
152\VerbatimInput{../eyes/Ogen.java}
153%Newpage
154\subsection{first/Database.java}
155\label{file:Database.java}
156\VerbatimInput{../first/Database.java}
157%Newpage
158\subsection{second/Database.java}
159\label{file:secondDatabase.java}
160\VerbatimInput{../second/Database.java}
161%Newpage
162\subsection{RWProblem.java}
163\label{file:RWProblem.java}
164\VerbatimInput{../first/RWProblem.java}
165%Newpage
166
167\end{document}
Note: See TracBrowser for help on using the repository browser.