Skip to content

Commit 706d446

Browse files
author
Vladimir Kotal
committed
translate SYS V semaphore API slide
1 parent a5e6ce6 commit 706d446

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

sys-v-semaphores.tex

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,46 @@
88
\texttt{int \funnm{semget}(key\_t \emph{key}, int \emph{nsems}, int
99
\emph{semflg});}
1010
\begin{itemize}
11-
\item vrátí identifikátor pole obsahujícího \texttt{nsems} semaforů asociovaný
12-
s~klíčem \texttt{key} (klíč \texttt{IPC\_PRIVATE} \dots{} privátní semafory, při
13-
každém použití vrátí jiný identifikátor). \texttt{semflg} je OR-kombinace
14-
přístupových práv a konstant \texttt{IPC\_CREAT} (vytvořit, pokud neexistuje),
15-
\texttt{IPC\_EXCL} (chyba, pokud existuje).
11+
\item returns identifier of an array of \texttt{nsems} semaphores associated
12+
with the \texttt{key} key (\texttt{IPC\_PRIVATE} key \dots{} private semaphores,
13+
each call returns different identifier).
14+
\texttt{semflg} is OR-combination of access rights and constants
15+
\texttt{IPC\_CREAT} (create if does not exist),
16+
\texttt{IPC\_EXCL} (error, if exists).
1617
\end{itemize}
1718
\texttt{int \funnm{semctl}(int \emph{semid}, int \emph{semnum},
1819
int \emph{cmd}, ...);}
1920
\begin{itemize}
20-
\item řídicí funkce, volitelný čtvrtý parametr \texttt{arg} je typu
21-
\texttt{union~semun}.
21+
\item controlling function, optional 4th argument \texttt{arg} is of the
22+
\texttt{union~semun} type.
2223
\end{itemize}
2324
\texttt{int \funnm{semop}(int \emph{semid}, struct sembuf *\emph{sops}, size\_t
2425
\emph{nsops});}
2526
\begin{itemize}
26-
\item zobecněné operace P a V.
27+
\item generic operations P and V.
2728
\end{itemize}
2829
\end{slide}
2930

3031
\label{SYSVSEM}
3132

3233
\begin{itemize}
33-
\item jak získat klíč pro \texttt{semget} je vysvětleno na strane
34+
\item How to get the key for \texttt{semget} is explained on page
3435
\pageref{FTOK}.
35-
\item největší zajímavost na System V implementaci semaforů je skutečnost, že
36-
daný syscall neoperuje nad jedním semaforem, ale nad \emsl{polem semaforů}, a to
37-
atomicky. Většinou však budete potřebovat pouze jeden semafor, tj. pole o jednom
38-
prvku. Pro takové použití jsou System V semafory zbytečně složité.
39-
\item přístupová práva jsou jen pro čtení a zápis; bit execute zde nemá smysl.
40-
\item podobné schéma API funkcí (funkce na vytvoření, řízení a operace) dodržují
41-
i ostatní System V IPC mechanismy.
42-
\item jakmile je jednou pole semaforů jedním procesem vytvořeno, mohou i ostatní
43-
procesy použít \texttt{semctl()} a \texttt{semop()}, aniž by předtím volaly
44-
\texttt{semget()}. To platí i pro semafory vytvořené s klíčem
45-
\texttt{IPC\_PRIVATE}, pro které nelze volat \texttt{semget()}, protože by se
46-
tím vytvořilo nové pole semaforů. Je to tak proto, aby i privátní semafory mohly
47-
být děděné v rámci \texttt{fork}.
36+
\item The most interesting property of System V semaphore implementation is
37+
that given syscall does not operate on one semaphore but on \emsl{semaphore
38+
array}, atomically.
39+
Most of the time you will need just one semaphore, i.e. array of one item.
40+
For such use the System V semaphores are needlessly complex.
41+
\item Access rights are only for reading and writing; the execute bit does not
42+
make sense in this context.
43+
\item Similar API (function for creating, control and operations) is followed by
44+
the other System V IPC mechanism as well.
45+
\item Once the array of semaphores is created by a process, the other processes
46+
can use \texttt{semctl()} and \texttt{semop()}, without calling
47+
\texttt{semget()} beforehand. This is valid also for the semaphores created with
48+
the \texttt{IPC\_PRIVATE} key, for which it is not possible to call
49+
\texttt{semget()}, because it would create new semaphore array. This is done so
50+
that private semaphores can be inherited across \texttt{fork} as well.
4851
\end{itemize}
4952

5053
%%%%%

0 commit comments

Comments
 (0)