|
15 | 15 | \begin{slide} |
16 | 16 | \sltitle{Problem: conflict while sharing data} |
17 | 17 | \begin{itemize} |
| 18 | +ifdef([[[NOSPELLCHECK]]], [[[ |
18 | 19 | \item \texttt{struct \{ int a, b; \} \emph{shared};} |
| 20 | +]]]) |
19 | 21 | \item |
20 | 22 | \begin{alltt} |
21 | 23 | for( ; ; ) \{ |
|
59 | 61 |
|
60 | 62 | \begin{slide} |
61 | 63 | \sltitle{Conflict scenario} |
| 64 | +ifdef([[[NOSPELLCHECK]]], [[[ |
62 | 65 | \begin{tabular}{rl@{\hspace{2cm}}|c|c|} |
| 66 | +]]]) |
63 | 67 | \multicolumn{2}{l}{Processes \emsl{A}\texttt{(val==1)} and |
64 | 68 | \emsl{B}\texttt{(val==2)}} & \multicolumn{1}{c}{\texttt{a}} & |
65 | 69 | \multicolumn{1}{c}{\texttt{b}}\\ |
|
102 | 106 | \item it is necessary to ensure atomic operation on the structure, i.e. |
103 | 107 | while one processes modifies the structure, the other cannot manipulate it. |
104 | 108 | \end{itemize} |
| 109 | +ifdef([[[NOSPELLCHECK]]], [[[ |
105 | 110 | \begin{tabular}{rl@{\hspace{2cm}}|c|c|} |
| 111 | +]]]) |
106 | 112 | \multicolumn{2}{l}{Processes \emsl{A}\texttt{(val==1)} and |
107 | 113 | \emsl{B}\texttt{(val==2)}} & \multicolumn{1}{c}{\texttt{a}} & |
108 | 114 | \multicolumn{1}{c}{\texttt{b}}\\ |
|
280 | 286 | that created the lock to the lock file. The process that is waiting for unlock |
281 | 287 | can verify that the process with given PID number exists. If not, it can remove |
282 | 288 | the lock file and retry. User level command that can do this is e.g. |
283 | | -\emsl{shlock}(1) (on FreeBSD in \texttt{/usr/ports/sysutils/shlock}), however |
284 | | -could cause situation in the following paragraph: |
| 289 | +\emsl{\texttt{shlock}}(1) (on FreeBSD in \texttt{/usr/ports/sysutils/shlock}), |
| 290 | +however could cause situation in the following paragraph: |
285 | 291 | \item \emsl{watch out:} if multiple processes find out simultaneously that |
286 | 292 | the process does not exist, it can lead to error. First process deletes the |
287 | 293 | lock file and creates new one with its PID. Next process does the same, |
|
337 | 343 | (e.g. \texttt{lockd} implements just advisory locking) |
338 | 344 | \item for given file they are enabled by setting the SGID bit and |
339 | 345 | removing right to execute for the group |
340 | | - (tj. setting that otherwise does not make sense). |
| 346 | + (i.e. setting that otherwise does not make sense). |
341 | 347 | One process sets the lock (e.g. using \texttt{fcntl}). Other processes |
342 | 348 | then do not have to check the lock explicitly because each |
343 | 349 | \texttt{open/read/write} operation is checked by the kernel against |
|
515 | 521 | \end{slide} |
516 | 522 |
|
517 | 523 | \begin{itemize} |
518 | | -\item \emsl{P} is from dutch \uv{proberen te verlagen} -- try to |
519 | | -decrement, \emsl{V} from \uv{verhogen} -- increment. |
| 524 | +\item \emsl{P} is from dutch ifdef([[[NOSPELLCHECK]]], |
| 525 | +[[[\uv{proberen te verlagen}]]]) -- try to |
| 526 | +decrement, \emsl{V} from ifdef([[[NOSPELLCHECK]]], [[[\uv{verhogen}]]]) |
| 527 | +-- increment. |
520 | 528 | \item The \texttt{P(s)} and \texttt{V(s)} operations can be made generic: |
521 | 529 | the semaphore value is possible to change with any integer |
522 | 530 | \texttt{n} \dots{} \texttt{P(s,~n)}, \texttt{V(s,~n)}. |
523 | 531 | \item Allen B. Downey: \emph{The Little Book of Semaphores}, Second Edition, |
524 | | -on-line na \url{http://greenteapress.com/semaphores/} |
| 532 | +on \url{http://greenteapress.com/semaphores/} |
525 | 533 | \item \emph{binary semaphore} has only values 0 or 1 |
526 | 534 | \end{itemize} |
527 | 535 |
|
|
559 | 567 |
|
560 | 568 | %%%%% |
561 | 569 |
|
| 570 | +ifdef([[[NOSPELLCHECK]]], [[[ |
562 | 571 | \pdfbookmark[1]{sem\_open, sem\_wait, sam\_post, sem\_close}{posix-semaphores} |
| 572 | +]]]) |
563 | 573 |
|
564 | 574 | \label{NAMED_SEMAPHORES} |
565 | 575 | \begin{slide} |
566 | 576 | \sltitle{POSIX API for semaphores} |
567 | 577 |
|
568 | 578 | \begin{minipage}{\slidewidth}\vspace{-1\baselineskip}\texttt{\begin{tabbing} |
| 579 | +ifdef([[[NOSPELLCHECK]]], [[[ |
569 | 580 | sem\_t \funnm{sem\_open}(\=const *char \emph{name}, int \emph{oflag}, |
570 | 581 | \\\>mode\_t \emph{mode}, unsigned int \emph{value}); |
| 582 | +]]]) |
571 | 583 | \end{tabbing}} |
572 | 584 | \end{minipage} |
573 | 585 | \begin{itemize} |
574 | 586 | \item creates or opens a new POSIX semaphore. \emph{mode} is same as for |
575 | 587 | \funnm{open}(). Use ``\texttt{/somename}'' for the \emph{name}. |
576 | 588 | \end{itemize} |
| 589 | +ifdef([[[NOSPELLCHECK]]], [[[ |
577 | 590 | \texttt{int \funnm{sem\_wait}(sem\_t *\emph{sem});} |
| 591 | +]]]) |
578 | 592 | \begin{itemize} |
579 | | -\item decrement \emph{sem}, if currently 0, the call will block |
| 593 | +\item decrement \emph{\texttt{sem}}, if currently 0, the call will block |
580 | 594 | \end{itemize} |
| 595 | +ifdef([[[NOSPELLCHECK]]], [[[ |
581 | 596 | \texttt{int \funnm{sem\_post}(sem\_t *\emph{sem});} |
| 597 | +]]]) |
582 | 598 | \begin{itemize} |
583 | | -\item increment \emph{sem}. If \emph{sem} consequently becomes greater than |
584 | | -0, another thread blocked in \funnm{sem\_wait}() will be woken up. |
| 599 | +\item increment \emph{\texttt{sem}}. If \emph{\texttt{sem}} consequently becomes |
| 600 | +greater than 0, another thread blocked in \funnm{sem\_wait}() will be woken up. |
585 | 601 | \end{itemize} |
| 602 | +ifdef([[[NOSPELLCHECK]]], [[[ |
586 | 603 | \texttt{int \funnm{sem\_close}(sem\_t *\emph{sem});} |
| 604 | +]]]) |
587 | 605 | \begin{itemize} |
588 | | -\item close \emph{sem}, free its resources allocated to \emsl{this} process. |
| 606 | +\item close \emph{\texttt{sem}}, free its resources allocated to \emsl{this} |
| 607 | +process. |
589 | 608 | \end{itemize} |
590 | 609 | \end{slide} |
591 | 610 |
|
592 | 611 | \begin{itemize} |
593 | | -\item \emph{oflag} can be a combination of only \texttt{O\_CREAT} and |
| 612 | +\item \emph{\texttt{oflag}} can be a combination of only \texttt{O\_CREAT} and |
594 | 613 | \texttt{O\_EXCL}. If the semaphore already exists, an invocation with only |
595 | 614 | \texttt{O\_CREAT} silently succeeds, \texttt{O\_EXCL} will cause an error. |
596 | 615 | \item As soon as the semaphore is created, other processes can use it as |
|
607 | 626 |
|
608 | 627 | %%%%% |
609 | 628 |
|
| 629 | +ifdef([[[NOSPELLCHECK]]], [[[ |
610 | 630 | \pdfbookmark[1]{shm\_open, sem\_open, mq\_open}{posixipc} |
| 631 | +]]]) |
611 | 632 |
|
612 | 633 | \begin{slide} |
613 | 634 | \sltitle{Other IPC facilities} |
|
0 commit comments