]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/semaphor.tex
remove C++ comment
[wxWidgets.git] / docs / latex / wx / semaphor.tex
CommitLineData
be809868
VZ
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%% Name: semaphore.tex
3%% Purpose: wxSemaphore documentation
4%% Author: Vadim Zeitlin
5%% Modified by:
6%% Created: 02.04.02
7%% RCS-ID: $Id$
8%% Copyright: (c) 2002 Vadim Zeitlin
8795498c 9%% License: wxWindows license
be809868
VZ
10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12\section{\class{wxSemaphore}}\label{wxsemaphore}
13
14wxSemaphore is a counter limiting the number of threads concurrently accessing
15a shared resource. This counter is always between $0$ and the maximum value
16specified during the semaphore creation. When the counter is strictly greater
17than $0$, a call to \helpref{Wait}{wxsemaphorewait} returns immediately and
18decrements the counter. As soon as it reaches $0$, any subsequent calls to
19\helpref{Wait}{wxsemaphorewait} block and only return when the semaphore
20counter becomes strictly positive again as the result of calling
21\helpref{Post}{wxsemaphorepost} which increments the counter.
22
90e572f1
MR
23In general, semaphores are useful to restrict access to a shared resource
24which can only be accessed by some fixed number of clients at the same time. For
be809868
VZ
25example, when modeling a hotel reservation system a semaphore with the counter
26equal to the total number of available rooms could be created. Each time a room
27is reserved, the semaphore should be acquired by calling
28\helpref{Wait}{wxsemaphorewait} and each time a room is freed it should be
29released by calling \helpref{Post}{wxsemaphorepost}.
30
31\wxheading{Derived from}
32
33No base class
34
35\wxheading{Include files}
36
37<wx/thread.h>
38
a7af285d
VZ
39\wxheading{Library}
40
41\helpref{wxBase}{librarieslist}
42
be809868
VZ
43\latexignore{\rtfignore{\wxheading{Members}}}
44
45\membersection{wxSemaphore::wxSemaphore}\label{wxsemaphorewxsemaphore}
46
47\func{}{wxSemaphore}{\param{int }{initialcount = 0}, \param{int }{maxcount = 0}}
48
49Specifying a {\it maxcount} of $0$ actually makes wxSemaphore behave as if
48d16e09
VZ
50there is no upper limit. If maxcount is $1$, the semaphore behaves almost as a
51mutex (but unlike a mutex it can be released by a thread different from the one
52which acquired it).
be809868
VZ
53
54{\it initialcount} is the initial value of the semaphore which must be between
55$0$ and {\it maxcount} (if it is not set to $0$).
56
57\membersection{wxSemaphore::\destruct{wxSemaphore}}\label{wxsemaphoredtor}
58
59\func{}{\destruct{wxSemaphore}}{\void}
60
61Destructor is not virtual, don't use this class polymorphically.
62
63\membersection{wxSemaphore::Post}\label{wxsemaphorepost}
64
b3e51e0f
VZ
65\func{wxSemaError }{Post}{\void}
66
67Increments the semaphore count and signals one of the waiting
2b5f62a0 68threads in an atomic way. Returns wxSEMA\_OVERFLOW if the count
b3e51e0f
VZ
69would increase the counter past the maximum.
70
71\wxheading{Return value}
72
73One of:
74
75\twocolwidtha{7cm}
76\begin{twocollist}\itemsep=0pt
77\twocolitem{{\bf wxSEMA\_NO\_ERROR}}{There was no error.}
78\twocolitem{{\bf wxSEMA\_INVALID}}{Semaphore hasn't been initialized successfully.}
79\twocolitem{{\bf wxSEMA\_OVERFLOW}}{Post() would increase counter past the max.}
80\twocolitem{{\bf wxSEMA\_MISC\_ERROR}}{Miscellaneous error.}
81\end{twocollist}
be809868 82
be809868
VZ
83
84\membersection{wxSemaphore::TryWait}\label{wxsemaphoretrywait}
85
b3e51e0f
VZ
86\func{wxSemaError }{TryWait}{\void}
87
88Same as \helpref{Wait()}{wxsemaphorewait}, but returns immediately.
89
90\wxheading{Return value}
91
92One of:
93
94\twocolwidtha{7cm}
95\begin{twocollist}\itemsep=0pt
96\twocolitem{{\bf wxSEMA\_NO\_ERROR}}{There was no error.}
97\twocolitem{{\bf wxSEMA\_INVALID}}{Semaphore hasn't been initialized successfully.}
98\twocolitem{{\bf wxSEMA\_BUSY}}{Returned by TryWait() if Wait() would block, i.e. the count is zero.}
99\twocolitem{{\bf wxSEMA\_MISC\_ERROR}}{Miscellaneous error.}
100\end{twocollist}
be809868 101
be809868
VZ
102
103\membersection{wxSemaphore::Wait}\label{wxsemaphorewait}
104
b3e51e0f 105\func{wxSemaError }{Wait}{\void}
be809868
VZ
106
107Wait indefinitely until the semaphore count becomes strictly positive
108and then decrement it and return.
109
b3e51e0f
VZ
110\wxheading{Return value}
111
112One of:
113
114\twocolwidtha{7cm}
115\begin{twocollist}\itemsep=0pt
116\twocolitem{{\bf wxSEMA\_NO\_ERROR}}{There was no error.}
117\twocolitem{{\bf wxSEMA\_INVALID}}{Semaphore hasn't been initialized successfully.}
118\twocolitem{{\bf wxSEMA\_MISC\_ERROR}}{Miscellaneous error.}
119\end{twocollist}
120
121\membersection{wxSemaphore::WaitTimeout}\label{wxsemaphorewaittimeout}
122
123\func{wxSemaError }{WaitTimeout}{\param{unsigned
124long}{timeout\_millis}}
125
126Same as \helpref{Wait()}{wxsemaphorewait}, but with a timeout
127limit.
128
129\wxheading{Return value}
be809868 130
b3e51e0f 131One of:
be809868 132
b3e51e0f
VZ
133\twocolwidtha{7cm}
134\begin{twocollist}\itemsep=0pt
135\twocolitem{{\bf wxSEMA\_NO\_ERROR}}{There was no error.}
136\twocolitem{{\bf wxSEMA\_INVALID}}{Semaphore hasn't been initialized successfully.}
137\twocolitem{{\bf wxSEMA\_TIMEOUT}}{Timeout occurred without receiving semaphore.}
138\twocolitem{{\bf wxSEMA\_MISC\_ERROR}}{Miscellaneous error.}
139\end{twocollist}