1QSemaphore(3qt)                                                QSemaphore(3qt)
2
3
4

NAME

6       QSemaphore - Robust integer semaphore
7

SYNOPSIS

9       All the functions in this class are thread-safe when Qt is built with
10       thread support.</p>
11
12       #include <qsemaphore.h>
13
14   Public Members
15       QSemaphore ( int maxcount )
16       virtual ~QSemaphore ()
17       int available () const
18       int total () const
19       int operator++ ( int )
20       int operator-- ( int )
21       int operator+= ( int n )
22       int operator-= ( int n )
23       bool tryAccess ( int n )
24

DESCRIPTION

26       The QSemaphore class provides a robust integer semaphore.
27
28       A QSemaphore can be used to serialize thread execution, in a similar
29       way to a QMutex. A semaphore differs from a mutex, in that a semaphore
30       can be accessed by more than one thread at a time.
31
32       For example, suppose we have an application that stores data in a large
33       tree structure. The application creates 10 threads (commonly called a
34       thread pool) to perform searches on the tree. When the application
35       searches the tree for some piece of data, it uses one thread per base
36       node to do the searching. A semaphore could be used to make sure that
37       two threads don't try to search the same branch of the tree at the same
38       time.
39
40       A non-computing example of a semaphore would be dining at a restuarant.
41       A semaphore is initialized to have a maximum count equal to the number
42       of chairs in the restuarant. As people arrive, they want a seat. As
43       seats are filled, the semaphore is accessed, once per person. As people
44       leave, the access is released, allowing more people to enter. If a
45       party of 10 people want to be seated, but there are only 9 seats, those
46       10 people will wait, but a party of 4 people would be seated (taking
47       the available seats to 5, making the party of 10 people wait longer).
48
49       When a semaphore is created it is given a number which is the maximum
50       number of concurrent accesses it will permit. Accesses to the sempahore
51       are gained using operator++() or operator+=(), and released with
52       operator--() or operator-=(). The number of accesses allowed is
53       retrieved with available(), and the total number with total(). Note
54       that the incrementing functions will block if there aren't enough
55       available accesses. Use tryAccess() if you want to acquire accesses
56       without blocking.
57
58       See also Environment Classes and Threading.
59

MEMBER FUNCTION DOCUMENTATION

QSemaphore::QSemaphore ( int maxcount )

62       Creates a new semaphore. The semaphore can be concurrently accessed at
63       most maxcount times.
64

QSemaphore::~QSemaphore () [virtual]

66       Destroys the semaphore.
67
68       Warning: If you destroy a semaphore that has accesses in use the
69       resultant behavior is undefined.
70

int QSemaphore::available () const

72       Returns the number of accesses currently available to the semaphore.
73

int QSemaphore::operator++ ( int )

75       Postfix ++ operator.
76
77       Try to get access to the semaphore. If available() == 0, this call will
78       block until it can get access, i.e. until available() > 0.
79

int QSemaphore::operator+= ( int n )

81       Try to get access to the semaphore. If available() < n, this call will
82       block until it can get all the accesses it wants, i.e. until
83       available() >= n.
84

int QSemaphore::operator-- ( int )

86       Postfix -- operator.
87
88       Release access of the semaphore. This wakes all threads waiting for
89       access to the semaphore.
90

int QSemaphore::operator-= ( int n )

92       Release n accesses to the semaphore.
93

int QSemaphore::total () const

95       Returns the total number of accesses to the semaphore.
96

bool QSemaphore::tryAccess ( int n )

98       Try to get access to the semaphore. If available() < n, this function
99       will return FALSE immediately. If available() >= n, this function will
100       take n accesses and return TRUE. This function does not block.
101
102

SEE ALSO

104       http://doc.trolltech.com/qsemaphore.html
105       http://www.trolltech.com/faq/tech.html
106
108       Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
109       license file included in the distribution for a complete license
110       statement.
111

AUTHOR

113       Generated automatically from the source code.
114

BUGS

116       If you find a bug in Qt, please report it as described in
117       http://doc.trolltech.com/bughowto.html.  Good bug reports help us to
118       help you. Thank you.
119
120       The definitive Qt documentation is provided in HTML format; it is
121       located at $QTDIR/doc/html and can be read using Qt Assistant or with a
122       web browser. This man page is provided as a convenience for those users
123       who prefer man pages, although this format is not officially supported
124       by Trolltech.
125
126       If you find errors in this manual page, please report them to qt-
127       bugs@trolltech.com.  Please include the name of the manual page
128       (qsemaphore.3qt) and the Qt version (3.3.8).
129
130
131
132Trolltech AS                    2 February 2007                QSemaphore(3qt)
Impressum