Skip to content

Commit 6a1666a

Browse files
author
Vladimir Kotal
committed
translate SysV semaphore API slides
1 parent 706d446 commit 6a1666a

File tree

1 file changed

+38
-43
lines changed

1 file changed

+38
-43
lines changed

sys-v-semaphores.tex

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -56,75 +56,70 @@
5656
\sltitle{System V semaphore API: \texttt{semctl()}}
5757
\setlength{\baselineskip}{0.9\baselineskip}
5858
\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}:
6161
\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}
6464
\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
7269
\texttt{arg.array}
73-
\item \texttt{SETALL} \dots{} nastaví všechny semafory podle
70+
\item \texttt{SETALL} \dots{} sets all sem. values according to
7471
\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
8076
\end{itemize}
8177
\end{itemize}
8278
\end{slide}
8379

8480
\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)}.
8783
\end{itemize}
8884

8985
%%%%%
9086

9187
\begin{slide}
9288
\sltitle{System V semaphore API: \texttt{semop()}}
9389
\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:
9793
\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
10096
\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}
104100
\end{itemize}
105-
\item \texttt{sem\_flg} \dots{} OR-kombinace
101+
\item \texttt{sem\_flg} \dots{} OR-combination
106102
\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
111107
\end{itemize}
112108
\end{itemize}
113109
\end{itemize}
114110
\end{slide}
115111

116112
\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.
128123
\end{itemize}
129124

130125
%%%%%

0 commit comments

Comments
 (0)