thesis/src/alg/par/comp/barrier.tex

18 lines
764 B
TeX

\begin{algorithmic}[1]
\Procedure{barrière}{} \Comment{procédure exécutée par les $N_t$ \en{threads}}
\State $\Call{P}{m}$ \Comment{sémaphore utilisé comme \en{mutex} pour protéger $N_b$}
\State $N_b \gets N_b + 1$ \Comment{$N_b$ compte le nombre de \en{thread} arrivés}
\If{$N_b = N_t$} \Comment{Le dernier \en{thread} exécutera la première branche}
\State $N_b \gets N_b - 1$
\Repeat
\State $\Call{V}{b}$ \Comment{libération des autres \en{threads}}
\State $N_b \gets N_b - 1$
\Until{$N_b = 0$}
\State $\Call{V}{m}$
\Else \Comment{pour les $N_t-1$ premiers \en{threads}}
\State $\Call{V}{m}$
\State $\Call{P}{b}$ \Comment{bloqué jusqu'à l'arrivée du dernier \en{thread}}
\EndIf
\EndProcedure
\end{algorithmic}