<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="fr">
	<id>https://tala-informatique.fr/index.php?action=history&amp;feed=atom&amp;title=C_semaphore</id>
	<title>C semaphore - Historique des versions</title>
	<link rel="self" type="application/atom+xml" href="https://tala-informatique.fr/index.php?action=history&amp;feed=atom&amp;title=C_semaphore"/>
	<link rel="alternate" type="text/html" href="https://tala-informatique.fr/index.php?title=C_semaphore&amp;action=history"/>
	<updated>2026-05-30T15:24:12Z</updated>
	<subtitle>Historique des versions pour cette page sur le wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://tala-informatique.fr/index.php?title=C_semaphore&amp;diff=3272&amp;oldid=prev</id>
		<title>Magsss : /* Initialisation */</title>
		<link rel="alternate" type="text/html" href="https://tala-informatique.fr/index.php?title=C_semaphore&amp;diff=3272&amp;oldid=prev"/>
		<updated>2018-11-01T18:05:04Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Initialisation&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;fr&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Version précédente&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Version du 1 novembre 2018 à 20:05&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l22&quot;&gt;Ligne 22 :&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Ligne 22 :&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*semaphore &amp;amp;rarr; pointeur vers le sémaphore à initialiser ;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*semaphore &amp;amp;rarr; pointeur vers le sémaphore à initialiser ;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*pshared &amp;amp;rarr; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;drapeaux &lt;/del&gt;qui précise si le sémaphore est utilisé par des threads (valeur &#039;&#039;0&#039;&#039;) ;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*pshared &amp;amp;rarr; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;drapeau &lt;/ins&gt;qui précise si le sémaphore est utilisé par des threads (valeur &#039;&#039;0&#039;&#039;) ;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*valeur  &amp;amp;rarr; valeur de départ du sémaphore.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*valeur  &amp;amp;rarr; valeur de départ du sémaphore.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* le code retour varie entre:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* le code retour varie entre:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;** &amp;#039;0&amp;#039; si tout s&amp;#039;est bien passé&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;** &amp;#039;0&amp;#039; si tout s&amp;#039;est bien passé&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;** &amp;#039;1&amp;#039; si une erreur survient et errno est positionné&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;** &amp;#039;1&amp;#039; si une erreur survient et errno est positionné&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Blocage ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Blocage ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Une fois le sémaphore initialisé, on peut demander son blocage avec&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Une fois le sémaphore initialisé, on peut demander son blocage avec&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key my_wiki-mediawiki-:diff:1.41:old-3271:rev-3272:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Magsss</name></author>
	</entry>
	<entry>
		<id>https://tala-informatique.fr/index.php?title=C_semaphore&amp;diff=3271&amp;oldid=prev</id>
		<title>Magsss : /* Introduction */</title>
		<link rel="alternate" type="text/html" href="https://tala-informatique.fr/index.php?title=C_semaphore&amp;diff=3271&amp;oldid=prev"/>
		<updated>2018-11-01T18:04:21Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Introduction&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;fr&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Version précédente&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Version du 1 novembre 2018 à 20:04&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l4&quot;&gt;Ligne 4 :&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Ligne 4 :&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;On peut se demander quelle est la différence avec un [[C_pthread#Exclusion_mutuelle | mutex]] ?&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;On peut se demander quelle est la différence avec un [[C_pthread#Exclusion_mutuelle | mutex]] ?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Un [[C_pthread#Exclusion_mutuelle | mutex]] est un mécanisme de verrouillage utilisé pour synchroniser l&#039;accès à une ressource alors qu&#039;un sémaphore est un mécanisme de signalisation utilisé pour sérialiser l&#039;exécution dans une portion de code. Un peu comme si les processus se &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;passer &lt;/del&gt;le mot: &quot;J&#039;ai fini, tu peux y aller&quot;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Un [[C_pthread#Exclusion_mutuelle | mutex]] est un mécanisme de verrouillage utilisé pour synchroniser l&#039;accès à une ressource alors qu&#039;un sémaphore est un mécanisme de signalisation utilisé pour sérialiser l&#039;exécution dans une portion de code. Un peu comme si les processus se &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;passaient &lt;/ins&gt;le mot: &quot;J&#039;ai fini, tu peux y aller&quot;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Utilisation=&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Utilisation=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key my_wiki-mediawiki-:diff:1.41:old-3175:rev-3271:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Magsss</name></author>
	</entry>
	<entry>
		<id>https://tala-informatique.fr/index.php?title=C_semaphore&amp;diff=3175&amp;oldid=prev</id>
		<title>Jc.forton : /* Blocage */</title>
		<link rel="alternate" type="text/html" href="https://tala-informatique.fr/index.php?title=C_semaphore&amp;diff=3175&amp;oldid=prev"/>
		<updated>2018-10-25T07:34:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Blocage&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;fr&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Version précédente&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Version du 25 octobre 2018 à 09:34&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l73&quot;&gt;Ligne 73 :&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Ligne 73 :&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Fichier:Warning-icon.png|40px]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Fichier:Warning-icon.png|40px]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|valign=&amp;quot;top&amp;quot;|&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|valign=&amp;quot;top&amp;quot;|&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  Cette fonction est &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;non &lt;/del&gt;bloquante le temps spécifié !&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  Cette fonction est bloquante le temps spécifié !&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Voici le détail de la structure &amp;#039;&amp;#039;timespec&amp;#039;&amp;#039;:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Voici le détail de la structure &amp;#039;&amp;#039;timespec&amp;#039;&amp;#039;:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key my_wiki-mediawiki-:diff:1.41:old-3174:rev-3175:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jc.forton</name></author>
	</entry>
	<entry>
		<id>https://tala-informatique.fr/index.php?title=C_semaphore&amp;diff=3174&amp;oldid=prev</id>
		<title>Jc.forton : /* Blocage */</title>
		<link rel="alternate" type="text/html" href="https://tala-informatique.fr/index.php?title=C_semaphore&amp;diff=3174&amp;oldid=prev"/>
		<updated>2018-10-25T07:34:07Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Blocage&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;fr&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Version précédente&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Version du 25 octobre 2018 à 09:34&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l61&quot;&gt;Ligne 61 :&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Ligne 61 :&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#include &amp;lt;semaphore.h&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#include &amp;lt;semaphore.h&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;#include &amp;lt;time.h&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;int sem_timedwait(sem_t *semaphore, const struct timespec *abs_timeout);&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;int sem_timedwait(sem_t *semaphore, const struct timespec *abs_timeout);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l81&quot;&gt;Ligne 81 :&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Ligne 82 :&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;};&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;};&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Relâchement d&amp;#039;un sémaphore ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Relâchement d&amp;#039;un sémaphore ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Une fois la section critique passée, on peut relâcher le sémaphore:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Une fois la section critique passée, on peut relâcher le sémaphore:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key my_wiki-mediawiki-:diff:1.41:old-3167:rev-3174:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jc.forton</name></author>
	</entry>
	<entry>
		<id>https://tala-informatique.fr/index.php?title=C_semaphore&amp;diff=3167&amp;oldid=prev</id>
		<title>Jc.forton : Page créée avec « = Introduction = Les sémaphores permettent de gérer ce que l&#039;on appelle les sections critiques. Il y a des parties de code où l&#039;on souhaite que toutes les instructions... »</title>
		<link rel="alternate" type="text/html" href="https://tala-informatique.fr/index.php?title=C_semaphore&amp;diff=3167&amp;oldid=prev"/>
		<updated>2018-10-22T18:36:04Z</updated>

		<summary type="html">&lt;p&gt;Page créée avec « = Introduction = Les sémaphores permettent de gérer ce que l&amp;#039;on appelle les sections critiques. Il y a des parties de code où l&amp;#039;on souhaite que toutes les instructions... »&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nouvelle page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Introduction =&lt;br /&gt;
Les sémaphores permettent de gérer ce que l&amp;#039;on appelle les sections critiques. Il y a des parties de code où l&amp;#039;on souhaite que toutes les instructions soient exécutées en évitant les interblocages un peu comme avec un [[C_pthread#Exclusion_mutuelle | mutex]].&lt;br /&gt;
&lt;br /&gt;
On peut se demander quelle est la différence avec un [[C_pthread#Exclusion_mutuelle | mutex]] ?&lt;br /&gt;
&lt;br /&gt;
Un [[C_pthread#Exclusion_mutuelle | mutex]] est un mécanisme de verrouillage utilisé pour synchroniser l&amp;#039;accès à une ressource alors qu&amp;#039;un sémaphore est un mécanisme de signalisation utilisé pour sérialiser l&amp;#039;exécution dans une portion de code. Un peu comme si les processus se passer le mot: &amp;quot;J&amp;#039;ai fini, tu peux y aller&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= Utilisation=&lt;br /&gt;
== Création ==&lt;br /&gt;
Tout d&amp;#039;abord, il faut créer un objet de type sémaphore:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;semaphore.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
sem_t semaphore;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
== Initialisation ==&lt;br /&gt;
Une fois l&amp;#039;objet créé, on peut l&amp;#039;initialiser:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;semaphore.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int sem_init(sem_t *semaphore, int pshared, unsigned int valeur);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
*semaphore &amp;amp;rarr; pointeur vers le sémaphore à initialiser ;&lt;br /&gt;
*pshared &amp;amp;rarr; drapeaux qui précise si le sémaphore est utilisé par des threads (valeur &amp;#039;&amp;#039;0&amp;#039;&amp;#039;) ;&lt;br /&gt;
*valeur  &amp;amp;rarr; valeur de départ du sémaphore.&lt;br /&gt;
* le code retour varie entre:&lt;br /&gt;
** &amp;#039;0&amp;#039; si tout s&amp;#039;est bien passé&lt;br /&gt;
** &amp;#039;1&amp;#039; si une erreur survient et errno est positionné&lt;br /&gt;
== Blocage ==&lt;br /&gt;
Une fois le sémaphore initialisé, on peut demander son blocage avec&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;semaphore.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int sem_wait(sem_t *semaphore);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
*semaphore &amp;amp;rarr; pointeur vers le sémaphore à bloquer ;&lt;br /&gt;
* le code retour varie entre:&lt;br /&gt;
** &amp;#039;0&amp;#039; si tout s&amp;#039;est bien passé&lt;br /&gt;
** &amp;#039;-1&amp;#039; si une erreur survient et errno est positionné&lt;br /&gt;
{|style=&amp;quot;width:350px&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
[[Fichier:Warning-icon.png|40px]]&lt;br /&gt;
|valign=&amp;quot;top&amp;quot;|&lt;br /&gt;
 Cette fonction est bloquante !&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;semaphore.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int sem_trywait(sem_t *semaphore);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
*semaphore &amp;amp;rarr; pointeur vers le sémaphore à bloquer ;&lt;br /&gt;
* le code retour varie entre:&lt;br /&gt;
** &amp;#039;0&amp;#039; si tout s&amp;#039;est bien passé&lt;br /&gt;
** &amp;#039;-1&amp;#039; si une erreur survient et errno est positionné&lt;br /&gt;
{|style=&amp;quot;width:380px&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
[[Fichier:Warning-icon.png|40px]]&lt;br /&gt;
|valign=&amp;quot;top&amp;quot;|&lt;br /&gt;
 Cette fonction est non bloquante !&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;semaphore.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int sem_timedwait(sem_t *semaphore, const struct timespec *abs_timeout);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
*semaphore &amp;amp;rarr; pointeur vers le sémaphore à bloquer ;&lt;br /&gt;
* le code retour varie entre:&lt;br /&gt;
** &amp;#039;0&amp;#039; si tout s&amp;#039;est bien passé&lt;br /&gt;
** &amp;#039;-1&amp;#039; si une erreur survient et errno est positionné&lt;br /&gt;
{|style=&amp;quot;width:380px&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
[[Fichier:Warning-icon.png|40px]]&lt;br /&gt;
|valign=&amp;quot;top&amp;quot;|&lt;br /&gt;
 Cette fonction est non bloquante le temps spécifié !&lt;br /&gt;
|}&lt;br /&gt;
Voici le détail de la structure &amp;#039;&amp;#039;timespec&amp;#039;&amp;#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
struct timespec {&lt;br /&gt;
   time_t tv_sec;      /* Seconds */&lt;br /&gt;
   long   tv_nsec;     /* Nanoseconds [0 .. 999999999] */&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
== Relâchement d&amp;#039;un sémaphore ==&lt;br /&gt;
Une fois la section critique passée, on peut relâcher le sémaphore:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;semaphore.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int sem_post(sem_t *semaphore);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
*semaphore &amp;amp;rarr; pointeur vers le sémaphore à bloquer ;&lt;br /&gt;
* le code retour varie entre:&lt;br /&gt;
** &amp;#039;0&amp;#039; si tout s&amp;#039;est bien passé&lt;br /&gt;
** &amp;#039;-1&amp;#039; si une erreur survient et errno est positionné&lt;br /&gt;
=Exemple=&lt;br /&gt;
Ci-dessous un exemple d&amp;#039;utilisation d&amp;#039;un sémaphore:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/wait.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;pthread.h&amp;gt;&lt;br /&gt;
#include &amp;lt;errno.h&amp;gt;&lt;br /&gt;
#include &amp;lt;semaphore.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define NB_THREAD 4&lt;br /&gt;
#define LIMIT 2&lt;br /&gt;
&lt;br /&gt;
// Création du sémaphore;&lt;br /&gt;
sem_t semaphore;&lt;br /&gt;
&lt;br /&gt;
void * job(void * args) {&lt;br /&gt;
	// Récupération de l&amp;#039;identifiant du thread&lt;br /&gt;
	int tid = pthread_self();&lt;br /&gt;
	int i = 0;&lt;br /&gt;
	while (i &amp;lt; LIMIT) {&lt;br /&gt;
		// On attend la disponibilité du sémaphore&lt;br /&gt;
		sem_wait(&amp;amp;semaphore);&lt;br /&gt;
		// Section critique&lt;br /&gt;
		printf(&amp;quot;Je suis le thread [%i] et je vais dormir 1 seconde\n&amp;quot;, tid);&lt;br /&gt;
		sleep(1);&lt;br /&gt;
		printf(&amp;quot;Je suis le thread [%i] et j&amp;#039;ai fini ma sieste\n&amp;quot;, tid);&lt;br /&gt;
		// On relache le sémaphore&lt;br /&gt;
		sem_post(&amp;amp;semaphore);&lt;br /&gt;
		i++;&lt;br /&gt;
	}&lt;br /&gt;
	pthread_exit(EXIT_SUCCESS);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	// Création d&amp;#039;un tableau de thread&lt;br /&gt;
	pthread_t threads[NB_THREAD];&lt;br /&gt;
	// Initialisation du sémaphore&lt;br /&gt;
	sem_init(&amp;amp;semaphore, PTHREAD_PROCESS_SHARED, 1);&lt;br /&gt;
	for (int i = 0; i &amp;lt; NB_THREAD; i++) {&lt;br /&gt;
		int err;&lt;br /&gt;
		if ((err = pthread_create(&amp;amp;threads[i], NULL, job, NULL)) != 0) {&lt;br /&gt;
			printf(&amp;quot;Echec de la création du thread: [%s]&amp;quot;, strerror(err));&lt;br /&gt;
			return EXIT_FAILURE;;&lt;br /&gt;
		}&lt;br /&gt;
		printf(&amp;quot;Création du thread numéro %i\n&amp;quot;, i);&lt;br /&gt;
	}&lt;br /&gt;
	for (int i = 0; i &amp;lt; NB_THREAD; i++) {&lt;br /&gt;
		pthread_join(threads[i], NULL);&lt;br /&gt;
	}&lt;br /&gt;
	sem_destroy(&amp;amp;semaphore);&lt;br /&gt;
	return EXIT_SUCCESS;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Ce programme donne, par exemple, la sortie suivante:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Création du thread numéro 0&lt;br /&gt;
Création du thread numéro 1&lt;br /&gt;
Création du thread numéro 2&lt;br /&gt;
Création du thread numéro 3&lt;br /&gt;
Je suis le thread [-1171347712] et je vais dormir 1 seconde&lt;br /&gt;
Je suis le thread [-1171347712] et j&amp;#039;ai fini ma sieste&lt;br /&gt;
Je suis le thread [-1171347712] et je vais dormir 1 seconde&lt;br /&gt;
Je suis le thread [-1171347712] et j&amp;#039;ai fini ma sieste&lt;br /&gt;
Je suis le thread [-1192327424] et je vais dormir 1 seconde&lt;br /&gt;
Je suis le thread [-1192327424] et j&amp;#039;ai fini ma sieste&lt;br /&gt;
Je suis le thread [-1192327424] et je vais dormir 1 seconde&lt;br /&gt;
Je suis le thread [-1192327424] et j&amp;#039;ai fini ma sieste&lt;br /&gt;
Je suis le thread [-1181837568] et je vais dormir 1 seconde&lt;br /&gt;
Je suis le thread [-1181837568] et j&amp;#039;ai fini ma sieste&lt;br /&gt;
Je suis le thread [-1181837568] et je vais dormir 1 seconde&lt;br /&gt;
Je suis le thread [-1181837568] et j&amp;#039;ai fini ma sieste&lt;br /&gt;
Je suis le thread [-1160857856] et je vais dormir 1 seconde&lt;br /&gt;
Je suis le thread [-1160857856] et j&amp;#039;ai fini ma sieste&lt;br /&gt;
Je suis le thread [-1160857856] et je vais dormir 1 seconde&lt;br /&gt;
Je suis le thread [-1160857856] et j&amp;#039;ai fini ma sieste&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
On voit bien les threads exécuter la section critique les uns après les autres !&lt;/div&gt;</summary>
		<author><name>Jc.forton</name></author>
	</entry>
</feed>