|
8 | 8 | \texttt{int \funnm{semget}(key\_t \emph{key}, int \emph{nsems}, int |
9 | 9 | \emph{semflg});} |
10 | 10 | \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). |
16 | 17 | \end{itemize} |
17 | 18 | \texttt{int \funnm{semctl}(int \emph{semid}, int \emph{semnum}, |
18 | 19 | int \emph{cmd}, ...);} |
19 | 20 | \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. |
22 | 23 | \end{itemize} |
23 | 24 | \texttt{int \funnm{semop}(int \emph{semid}, struct sembuf *\emph{sops}, size\_t |
24 | 25 | \emph{nsops});} |
25 | 26 | \begin{itemize} |
26 | | -\item zobecněné operace P a V. |
| 27 | +\item generic operations P and V. |
27 | 28 | \end{itemize} |
28 | 29 | \end{slide} |
29 | 30 |
|
30 | 31 | \label{SYSVSEM} |
31 | 32 |
|
32 | 33 | \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 |
34 | 35 | \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. |
48 | 51 | \end{itemize} |
49 | 52 |
|
50 | 53 | %%%%% |
|
0 commit comments