File: Semaphore.html

package info (click to toggle)
libape 1.0.0-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,572 kB
  • ctags: 1,343
  • sloc: sh: 7,342; cpp: 3,418; makefile: 117
file content (105 lines) | stat: -rw-r--r-- 3,866 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<HTML><HEAD><TITLE>Semaphore Class</TITLE></HEAD>
<BODY bgcolor="#ffffff">

<H1>Semaphore Class Reference</H1>
<p>
[<A HREF="index.html">APE Index</A>] [<A HREF="hier.html">APE Hierarchy</A>]
[<A HREF="header-list.html">Headers</A>]
</p>
<HR>
<P>Semaphore counter for thread synchronization.    <a href="#short">More...</a></P>
<P>
<code>
	#include &lt;<a href="thread-h.html">thread.h</a>&gt;
</code>

</P>

<H2>Public Members</H2>
<UL>
<LI> <b><a href="#ref0">Semaphore</a></b> (size_t resource = 0) 
</LI>
<LI> <b><a href="#ref1">~Semaphore</a></b> () 
</LI>
<LI>inline void <b><a href="#ref2">Wait</a></b> (void) 
</LI>
<LI>inline void <b><a href="#ref3">Post</a></b> (void) 
</LI>
</UL>

<H2>Protected Members</H2>
<UL>
<LI>	sem_t <b><a name="ref4">_semaphore</a></b>
</LI>
</UL>
<HR>
<H2><a name="short">Detailed Description</a></H2>
<P>

 A semaphore is generally used as a synchronization object between multiple
 threads or to protect a limited and finite resource such as a memory or
 thread pool.  The semaphore has a counter which only permits access by
 one or more threads when the value of the semaphore is non-zero.  Each
 access reduces the current value of the semaphore by 1.  One or more
 threads can wait on a semaphore until it is no longer 0, and hence the
 semaphore can be used as a simple thread synchronization object to enable
 one thread to pause others until the thread is ready or has provided data
 for them.
 

</P><HR>
<H3><b> <a name="ref0"></a><a name="Semaphore">Semaphore</a>(size_t resource = 0)  </b><code>[public]</code></H3>
<p>The initial value of the semaphore can be specified.  An initial
value is often used When used to lock a finite resource or to 
specify the maximum number of thread instances that can access a 
specified resource.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
resource</td><td align="left" valign="top">
specify initial resource count or 0 default.</td></tr>
</table>
</dl>
<H3><b> <a name="ref1"></a><a name="~Semaphore">~Semaphore</a>()  </b><code>[public]</code></H3>
<p>Destroying a semaphore also removes any system resources
associated with it.  If a semaphore has threads currently waiting
on it, those threads will all continue when a semaphore is
destroyed.
</p>
<H3><b>inline void <a name="ref2"></a><a name="Wait">Wait</a>(void)  </b><code>[public]</code></H3>
<p>Wait is used to keep a thread held until the semaphore counter
is greater than 0.  If the current thread is held, then another
thread must increment the semaphore.  Once the thread is accepted, 
the semaphore is automatically decremented, and the thread 
continues execution.
</p><p>
The pthread semaphore object does not support a timed "wait", and
hence to maintain consistancy, neither the posix nor win32 source
trees support "timed" semaphore objects.
</p><p>
</p>
<dl><dt><b>See Also</b>:<dd><a href="Semaphore.html#Post">Post</a></dl>
<H3><b>inline void <a name="ref3"></a><a name="Post">Post</a>(void)  </b><code>[public]</code></H3>
<p>Posting to a semaphore increments its current value and releases
the first thread waiting for the semaphore if it is currently at
0.  Interestingly, there is no support to increment a semaphore by
any value greater than 1 to release multiple waiting threads in
either pthread or the win32 API.  Hence, if one wants to release
a semaphore to enable multiple threads to execute, one must perform
multiple post operations.
</p><p>
</p>
<dl><dt><b>See Also</b>:<dd><a href="Semaphore.html#Wait">Wait</a></dl>
<HR>
<TABLE WIDTH="100%"><TR><TD ALIGN="left" VALIGN="top">

<UL><LI><I>Author</I>: David Sugar &lt;dyfet@ostel.com&gt; </LI>
<LI>Documentation generated by dyfet@home.sys on Thu Dec 16 09:54:26 EST 1999
</LI>
</UL></TD><TD ALIGN="RIGHT" VALIGN="TOP">
<b>K</b><i>doc</i>
</TD>
</TR></TABLE></BODY></HTML>