|
56 | 56 | \sltitle{System V semaphore API: \texttt{semctl()}} |
57 | 57 | \setlength{\baselineskip}{0.9\baselineskip} |
58 | 58 | \begin{itemize} |
59 | | -\item \texttt{semnum} \dots{} číslo semaforu v poli |
60 | | -\item možné hodnoty \texttt{cmd}: |
| 59 | +\item \texttt{semnum} \dots{} number of semaphore in the array |
| 60 | +\item possible values of \texttt{cmd}: |
61 | 61 | \begin{itemize} |
62 | | - \item \texttt{GETVAL} \dots{} vrátí hodnotu semaforu |
63 | | - \item \texttt{\emsl{SETVAL}} \dots{} \emsl{nastaví semafor na hodnotu} |
| 62 | + \item \texttt{GETVAL} \dots{} returns semaphore value |
| 63 | + \item \texttt{\emsl{SETVAL}} \dots{} \emsl{sets semaphore to value} |
64 | 64 | \texttt{arg.val} |
65 | | - \item \texttt{GETPID} \dots{} PID procesu, který provedl |
66 | | - poslední operaci |
67 | | - \item \texttt{GETNCNT} \dots{} počet procesů čekajících na větší |
68 | | - hodnotu |
69 | | - \item \texttt{GETZCNT} \dots{} počet procesů čekajících na nulu |
70 | | - \item \texttt{GETALL} \dots{} uloží hodnoty všech semaforů do |
71 | | - pole |
| 65 | + \item \texttt{GETPID} \dots{} PID of the process that performed the last op. |
| 66 | + \item \texttt{GETNCNT} \dots{} number of processes waiting on bigger value |
| 67 | + \item \texttt{GETZCNT} \dots{} number of processes waiting for zero value |
| 68 | + \item \texttt{GETALL} \dots{} saves the values of all semaphores to |
72 | 69 | \texttt{arg.array} |
73 | | - \item \texttt{SETALL} \dots{} nastaví všechny semafory podle |
| 70 | + \item \texttt{SETALL} \dots{} sets all sem. values according to |
74 | 71 | \texttt{arg.array} |
75 | | - \item \texttt{IPC\_STAT} \dots{} do \texttt{arg.buf} dá počet |
76 | | - semaforů, přístupová práva a časy posledních \texttt{semctl()} a |
77 | | - \texttt{semop()} |
78 | | - \item \texttt{IPC\_SET} \dots{} nastaví přístupová práva |
79 | | - \item \texttt{IPC\_RMID} \dots{} zruší pole semaforů |
| 72 | + \item \texttt{IPC\_STAT} \dots{} saves number of semaphores, access rights, |
| 73 | +times of the last \texttt{semctl()} and \texttt{semop()} into \texttt{arg.buf} |
| 74 | + \item \texttt{IPC\_SET} \dots{} sets access rights |
| 75 | + \item \texttt{IPC\_RMID} \dots{} destroys the semaphore array |
80 | 76 | \end{itemize} |
81 | 77 | \end{itemize} |
82 | 78 | \end{slide} |
83 | 79 |
|
84 | 80 | \begin{itemize} |
85 | | -\item volání \texttt{semctl(semid, semnum, SETVAL, arg)} odpovídá obecné |
86 | | -semaforové inicializační operaci \texttt{init(s,~n)}. |
| 81 | +\item The \texttt{semctl(semid, semnum, SETVAL, arg)} call corresponds to |
| 82 | +generic semaphore operation \texttt{init(s,~n)}. |
87 | 83 | \end{itemize} |
88 | 84 |
|
89 | 85 | %%%%% |
90 | 86 |
|
91 | 87 | \begin{slide} |
92 | 88 | \sltitle{System V semaphore API: \texttt{semop()}} |
93 | 89 | \begin{itemize} |
94 | | -\item operace se provádí atomicky (tj. buď se povede pro všechny |
95 | | -semafory, nebo pro žádný) na \texttt{nsops} semaforech podle pole |
96 | | -\texttt{sops} struktur \texttt{struct~sembuf}, která obsahuje: |
| 90 | +\item operation is performed atomically (i.e. either it will be done for all |
| 91 | +semaphores or none) on \texttt{nsops} semaphores according to the array |
| 92 | +\texttt{sops} of structures \texttt{struct~sembuf}, that contains: |
97 | 93 | \begin{itemize} |
98 | | - \item \texttt{sem\_num} \dots{} číslo semaforu |
99 | | - \item \texttt{sem\_op} \dots{} operace |
| 94 | + \item \texttt{sem\_num} \dots{} semaphore number |
| 95 | + \item \texttt{sem\_op} \dots{} operation |
100 | 96 | \begin{itemize} |
101 | | - \item \texttt{P(sem\_num, abs(sem\_op))} pro \texttt{sem\_op < 0} |
102 | | - \item \texttt{V(sem\_num, sem\_op)} pro \texttt{sem\_op > 0} |
103 | | - \item čekání na nulovou hodnotu semaforu pro \texttt{sem\_op == 0} |
| 97 | + \item \texttt{P(sem\_num, abs(sem\_op))} for \texttt{sem\_op < 0} |
| 98 | + \item \texttt{V(sem\_num, sem\_op)} for \texttt{sem\_op > 0} |
| 99 | + \item waiting on zero semaphore value for \texttt{sem\_op == 0} |
104 | 100 | \end{itemize} |
105 | | - \item \texttt{sem\_flg} \dots{} OR-kombinace |
| 101 | + \item \texttt{sem\_flg} \dots{} OR-combination |
106 | 102 | \begin{itemize} |
107 | | - \item \texttt{IPC\_NOWAIT} \dots{} když nelze operaci hned provést, |
108 | | - nečeká a vrátí chybu |
109 | | - \item \texttt{SEM\_UNDO} \dots{} při ukončení procesu vrátit |
110 | | - operace se semaforem |
| 103 | + \item \texttt{IPC\_NOWAIT} \dots{} when the operation cannot be |
| 104 | + performed it does not wait and returns error |
| 105 | + \item \texttt{SEM\_UNDO} \dots{} upon process exit undo the semaphore |
| 106 | + operations |
111 | 107 | \end{itemize} |
112 | 108 | \end{itemize} |
113 | 109 | \end{itemize} |
114 | 110 | \end{slide} |
115 | 111 |
|
116 | 112 | \begin{itemize} |
117 | | -\item atomičnost přes množinu semaforů zajistí, že nedojde k deadlocku |
118 | | -v následující situaci: dva procesy $A$ a $B$ budou používat dva semafory k |
119 | | -řízení přístupu (zamykání) ke dvěma systémovým zdrojům. Proces $A$ je bude |
120 | | -zamykat v pořadí $(0, 1)$ a proces $B$ v pořadí $(1, 0)$. Ve chvíli, |
121 | | -kdy proces $A$ zamkne semafor $0$ a $B$ zamkne $1$, dojde k |
122 | | -deadlocku, protože ani jeden proces nemůže pokračovat (potřeboval by |
123 | | -zamknout druhý semafor). Při použití atomické operace zamčení obou |
124 | | -semaforů najednou bude úspěšný vždy právě jeden proces, který získá |
125 | | -oba semafory, druhý bude čekat. |
126 | | -\item \texttt{SEM\_UNDO} zajistí, že při ukončení procesu dojde k odemčení |
127 | | -semaforů (po\-u\-ži\-tých jako zámky), které tento proces měl zamčené. |
| 113 | +\item The atomicity across the array avoids deadlock e.g. in this situation: |
| 114 | +two processes $A$ and $B$ will be using two semaphores for synchronization of |
| 115 | +access to two system resources. $A$ will lock in the $(0, 1)$ order and process |
| 116 | +$B$ will use the $(1, 0)$ order. In the moment when process $A$ locks semaphore |
| 117 | +$0$ and $B$ locks $1$, deadlock will happen because neither process can |
| 118 | +continue due to cyclical dependency. Using atomic operation of both semaphores |
| 119 | +means the operation will be successful only for one process that acquires both |
| 120 | +semaphores, the other will wait. |
| 121 | +\item \texttt{SEM\_UNDO} ensures that upon process exit the semaphore that were |
| 122 | +locked by the process (used as locks) will become unlocked. |
128 | 123 | \end{itemize} |
129 | 124 |
|
130 | 125 | %%%%% |
|
0 commit comments