Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / Thread / Semaphore.html
blobb2fb723bf5e47e751453a4a63859ae629397ceb1
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>Thread::Semaphore - thread-safe semaphores</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;Thread::Semaphore - thread-safe semaphores</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <li><a href="#functions_and_methods">FUNCTIONS AND METHODS</a></li>
26 </ul>
27 <!-- INDEX END -->
29 <hr />
30 <p>
31 </p>
32 <h1><a name="name">NAME</a></h1>
33 <p>Thread::Semaphore - thread-safe semaphores</p>
34 <p>
35 </p>
36 <hr />
37 <h1><a name="synopsis">SYNOPSIS</a></h1>
38 <pre>
39 use Thread::Semaphore;
40 my $s = new Thread::Semaphore;
41 $s-&gt;down; # Also known as the semaphore P operation.
42 # The guarded section is here
43 $s-&gt;up; # Also known as the semaphore V operation.</pre>
44 <pre>
45 # The default semaphore value is 1.
46 my $s = new Thread::Semaphore($initial_value);
47 $s-&gt;down($down_value);
48 $s-&gt;up($up_value);</pre>
49 <p>
50 </p>
51 <hr />
52 <h1><a name="description">DESCRIPTION</a></h1>
53 <p>Semaphores provide a mechanism to regulate access to resources. Semaphores,
54 unlike locks, aren't tied to particular scalars, and so may be used to
55 control access to anything you care to use them for.</p>
56 <p>Semaphores don't limit their values to zero or one, so they can be used to
57 control access to some resource that there may be more than one of. (For
58 example, filehandles.) Increment and decrement amounts aren't fixed at one
59 either, so threads can reserve or return multiple resources at once.</p>
60 <p>
61 </p>
62 <hr />
63 <h1><a name="functions_and_methods">FUNCTIONS AND METHODS</a></h1>
64 <dl>
65 <dt><strong><a name="item_new">new</a></strong>
67 <dt><strong>new NUMBER</strong>
69 <dd>
70 <p><a href="#item_new"><code>new</code></a> creates a new semaphore, and initializes its count to the passed
71 number. If no number is passed, the semaphore's count is set to one.</p>
72 </dd>
73 </li>
74 <dt><strong><a name="item_down">down</a></strong>
76 <dt><strong>down NUMBER</strong>
78 <dd>
79 <p>The <a href="#item_down"><code>down</code></a> method decreases the semaphore's count by the specified number,
80 or by one if no number has been specified. If the semaphore's count would drop
81 below zero, this method will block until such time that the semaphore's
82 count is equal to or larger than the amount you're <a href="#item_down"><code>down</code></a>ing the
83 semaphore's count by.</p>
84 </dd>
85 <dd>
86 <p>This is the semaphore ``P operation'' (the name derives from the Dutch
87 word ``pak'', which means ``capture'' -- the semaphore operations were
88 named by the late Dijkstra, who was Dutch).</p>
89 </dd>
90 </li>
91 <dt><strong><a name="item_up">up</a></strong>
93 <dt><strong>up NUMBER</strong>
95 <dd>
96 <p>The <a href="#item_up"><code>up</code></a> method increases the semaphore's count by the number specified,
97 or by one if no number has been specified. This will unblock any thread blocked
98 trying to <a href="#item_down"><code>down</code></a> the semaphore if the <a href="#item_up"><code>up</code></a> raises the semaphore count
99 above the amount that the <a href="#item_down"><code>down</code></a>s are trying to decrement it by.</p>
100 </dd>
101 <dd>
102 <p>This is the semaphore ``V operation'' (the name derives from the Dutch
103 word ``vrij'', which means ``release'').</p>
104 </dd>
105 </li>
106 </dl>
107 <table border="0" width="100%" cellspacing="0" cellpadding="3">
108 <tr><td class="block" style="background-color: #cccccc" valign="middle">
109 <big><strong><span class="block">&nbsp;Thread::Semaphore - thread-safe semaphores</span></strong></big>
110 </td></tr>
111 </table>
113 </body>
115 </html>