Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  chap8.html   Sprache: HTML

 
 products/Sources/formale Sprachen/GAP/doc/hpc/chap8.html


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>GAP (hpc) - Chapter 8: Semaphores</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
<script src="manual.js" type="text/javascript"></script>
<script type="text/javascript">overwriteStyle();</script>
</head>
<body class="chap8"  onload="jscontent()">


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chap11.html">11</a>  <a href="chapInd.html">Ind</a>  </div>

<div class="chlinkprevnexttop"> <a href="chap0.html">[Top of Book]</a>   <a href="chap0.html#contents">[Contents]</a>    <a href="chap7.html">[Previous Chapter]</a>    <a href="chap9.html">[Next Chapter]</a>   </div>

<p id="mathjaxlink" class="pcenter"><a href="chap8_mj.html">[MathJax on]</a></p>
<p><a id="X83F63F0F7827767E" name="X83F63F0F7827767E"></a></p>
<div class="ChapSects"><a href="chap8.html#X83F63F0F7827767E">8 <span class="Heading">Semaphores</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap8.html#X83F63F0F7827767E">8.1 <span class="Heading">Semaphores</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap8.html#X7AC5500483465AE3">8.1-1 CreateSemaphore</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap8.html#X834E47327A3FC5A2">8.1-2 WaitSemaphore</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap8.html#X7F0C1F1F8540CF8C">8.1-3 SignalSemaphore</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap8.html#X83D868417F0069F0">8.1-4 <span class="Heading">Simulating locks</span></a>
</span>
</div></div>
</div>

<h3>8 <span class="Heading">Semaphores</span></h3>

<p><a id="X83F63F0F7827767E" name="X83F63F0F7827767E"></a></p>

<h4>8.1 <span class="Heading">Semaphores</span></h4>

<p>Semaphores are synchronized counters; they can also be used to simulate locks.</p>

<p><a id="X7AC5500483465AE3" name="X7AC5500483465AE3"></a></p>

<h5>8.1-1 CreateSemaphore</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CreateSemaphore</code>( [<var class="Arg">value</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>The function <code class="func">CreateSemaphore</code> takes an optional argument, which defaults to zero. It is the counter with which the semaphore is initialized.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">sem := CreateSemaphore(1);</span>
<semaphore 0x1108e81c0: count = 1>
</pre></div>

<p><a id="X834E47327A3FC5A2" name="X834E47327A3FC5A2"></a></p>

<h5>8.1-2 WaitSemaphore</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ WaitSemaphore</code>( <var class="Arg">sem</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">WaitSemaphore</code> receives a previously created semaphore as its argument. If the semaphore's counter is greater than zero, it decrements the counter and returns; if the counter is zero, it waits until another thread increases it via SignalSemaphore (8.1-3), then decrements the counter and returns.




<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">sem := CreateSemaphore(1);</span>
<semaphore 0x1108e81c0: count = 1>
<span class="GAPprompt">gap></span> <span class="GAPinput">WaitSemaphore(sem);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">sem;</span>
<semaphore 0x1108e81c0: count = 0>
</pre></div>

<p><a id="X7F0C1F1F8540CF8C" name="X7F0C1F1F8540CF8C"></a></p>

<h5>8.1-3 SignalSemaphore</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SignalSemaphore</code>( <var class="Arg">sem</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">SignalSemaphore</code> receives a previously created semaphore as its argument. It increments the semaphore's counter and returns.




<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">sem := CreateSemaphore(1);</span>
<semaphore 0x1108e81c0: count = 1>
<span class="GAPprompt">gap></span> <span class="GAPinput">WaitSemaphore(sem);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">sem;</span>
<semaphore 0x1108e81c0: count = 0>
<span class="GAPprompt">gap></span> <span class="GAPinput">SignalSemaphore(sem);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">sem;</span>
<semaphore 0x1108e81c0: count = 1>
</pre></div>

<p><a id="X83D868417F0069F0" name="X83D868417F0069F0"></a></p>

<h5>8.1-4 <span class="Heading">Simulating locks</span></h5>

<p>In order to use semaphores to simulate locks, create a semaphore with an initial value of 1. <code class="func">WaitSemaphore</code> (<a href="chap8.html#X834E47327A3FC5A2"><span class="RefLink">8.1-2</span></a>) is then equivalent to a lock operation, <code class="func">SignalSemaphore</code> (<a href="chap8.html#X7F0C1F1F8540CF8C"><span class="RefLink">8.1-3</span></a>) is equivalent to an unlock operation.</p>


<div class="chlinkprevnextbot"> <a href="chap0.html">[Top of Book]</a>   <a href="chap0.html#contents">[Contents]</a>    <a href="chap7.html">[Previous Chapter]</a>    <a href="chap9.html">[Next Chapter]</a>   </div>


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chap11.html">11</a>  <a href="chapInd.html">Ind</a>  </div>

<hr />
<p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>

100%


¤ Dauer der Verarbeitung: 0.15 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge