Skip to content

Commit 55da044

Browse files
committed
More on synchronization.
1 parent 00065db commit 55da044

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

synchro.tex

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@
240240

241241
\begin{itemize}
242242
\item Both Dekker and Peterson need to achieve the result via only shared
243-
memory, i.e. several variables shared by processes.
243+
memory, i.e. several variables shared by processes. Busy waiting is used by
244+
both algorithms when waiting to enter the critical section already occupied by
245+
another process.
244246
\item Dekker's solution is presented as a first solution to the problem of
245247
mutual exclusion of 2 processes, without having to apply the mechanism of
246248
strict alternation, i.e. if second process does not express the will to enter
@@ -264,19 +266,20 @@
264266
\sltitle{Lock files}
265267
\begin{itemize}
266268
\item for each shared resource there exists previously agreed file path.
267-
Locking is done by creating the file, unlocking by removing the file.
268-
Each process must check if the file exists and if yes, has to wait.
269+
Locking is done by creating the file, unlocking by removing it. Each process
270+
must check if the file exists and wait if it does.
269271
\end{itemize}
270272
\begin{alltt}
271273
void \funnm{lock}(char *lockfile) \{
272-
while( (fd = open(lockfile,
273-
O\_RDWR|O\_CREAT|\emprg{O\_EXCL}, 0600)) == -1)
274-
sleep(1); {\rm /* waiting in a loop for unlock */}
275-
close(fd);
274+
while( (fd = open(lockfile,
275+
O\_RDWR|O\_CREAT|\emprg{O\_EXCL}, 0600)) == -1) \{
276+
sleep(1); {\rm/* waiting in a loop for unlock */}
277+
\}
278+
close(fd);
276279
\}
277280
278281
void \funnm{unlock}(char *lockfile) \{
279-
unlink(lockfile);
282+
unlink(lockfile);
280283
\}
281284
\end{alltt}
282285
\end{slide}
@@ -325,7 +328,7 @@
325328
\pdfbookmark[1]{fcntl}{fcntl}
326329

327330
\begin{slide}
328-
\sltitle{file locking: \texttt{fcntl()}}
331+
\sltitle{File locking: \texttt{fcntl()}}
329332
\texttt{int \funnm{fcntl}(int \emph{fildes}, int \emph{cmd}, ...);}
330333
\begin{itemize}
331334
\item to set locks for file \texttt{fildes}:
@@ -510,6 +513,7 @@
510513
the \texttt{ipcs} command. They can be deleted using the \texttt{ipcrm} command.
511514
The state and contents of existing IPS resources is unchanged even if no process
512515
works with them at the moment.
516+
\item For more information, see \texttt{svipc(7)} man page on any Linux distro.
513517
\end{itemize}
514518

515519
%%%%%

0 commit comments

Comments
 (0)