|
240 | 240 |
|
241 | 241 | \begin{itemize}
|
242 | 242 | \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. |
244 | 246 | \item Dekker's solution is presented as a first solution to the problem of
|
245 | 247 | mutual exclusion of 2 processes, without having to apply the mechanism of
|
246 | 248 | strict alternation, i.e. if second process does not express the will to enter
|
|
264 | 266 | \sltitle{Lock files}
|
265 | 267 | \begin{itemize}
|
266 | 268 | \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. |
269 | 271 | \end{itemize}
|
270 | 272 | \begin{alltt}
|
271 | 273 | 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); |
276 | 279 | \}
|
277 | 280 |
|
278 | 281 | void \funnm{unlock}(char *lockfile) \{
|
279 |
| - unlink(lockfile); |
| 282 | + unlink(lockfile); |
280 | 283 | \}
|
281 | 284 | \end{alltt}
|
282 | 285 | \end{slide}
|
|
325 | 328 | \pdfbookmark[1]{fcntl}{fcntl}
|
326 | 329 |
|
327 | 330 | \begin{slide}
|
328 |
| -\sltitle{file locking: \texttt{fcntl()}} |
| 331 | +\sltitle{File locking: \texttt{fcntl()}} |
329 | 332 | \texttt{int \funnm{fcntl}(int \emph{fildes}, int \emph{cmd}, ...);}
|
330 | 333 | \begin{itemize}
|
331 | 334 | \item to set locks for file \texttt{fildes}:
|
|
510 | 513 | the \texttt{ipcs} command. They can be deleted using the \texttt{ipcrm} command.
|
511 | 514 | The state and contents of existing IPS resources is unchanged even if no process
|
512 | 515 | works with them at the moment.
|
| 516 | +\item For more information, see \texttt{svipc(7)} man page on any Linux distro. |
513 | 517 | \end{itemize}
|
514 | 518 |
|
515 | 519 | %%%%%
|
|
0 commit comments