<class name="QSemaphore" doc="/**
&lt;p&gt;The &lt;a href=&quot;QSemaphore.html#QSemaphore(int)&quot;&gt;&lt;tt&gt;QSemaphore&lt;/tt&gt;&lt;/a&gt; class provides a general counting semaphore.&lt;/p&gt;
&lt;p&gt;A semaphore is a generalization of a mutex. While a mutex can only be locked once, it's possible to acquire a semaphore multiple times. Semaphores are typically used to protect a certain number of identical resources.&lt;/p&gt;
&lt;p&gt;Semaphores support two fundamental operations, &lt;a href=&quot;QSemaphore.html#acquire(int)&quot;&gt;&lt;tt&gt;acquire&lt;/tt&gt;&lt;/a&gt; and &lt;a href=&quot;QSemaphore.html#release(int)&quot;&gt;&lt;tt&gt;release&lt;/tt&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;acquire(&lt;i&gt;n&lt;/i&gt;) tries to acquire &lt;i&gt;n&lt;/i&gt; resources. If there aren't that many resources available, the call will block until this is the case.&lt;/li&gt;
&lt;li&gt;release(&lt;i&gt;n&lt;/i&gt;) releases &lt;i&gt;n&lt;/i&gt; resources.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There's also a &lt;a href=&quot;QSemaphore.html#tryAcquire(int, int)&quot;&gt;&lt;tt&gt;tryAcquire&lt;/tt&gt;&lt;/a&gt; function that returns immediately if it cannot acquire the resources, and an &lt;a href=&quot;QSemaphore.html#available()&quot;&gt;&lt;tt&gt;available&lt;/tt&gt;&lt;/a&gt; function that returns the number of available resources at any time.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;    QSemaphore sem(5);      &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 5

    sem.acquire(3);         &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 2
    sem.acquire(2);         &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 0
    sem.release(5);         &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 5
    sem.release(5);         &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 10

    sem.tryAcquire(1);      &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 9, returns true
    sem.tryAcquire(250);    &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 9, returns false&lt;/pre&gt;
&lt;p&gt;A typical application of semaphores is for controlling access to a circular buffer shared by a producer thread and a consumer thread. The Semaphores&lt;/tt&gt; example shows how to use &lt;a href=&quot;QSemaphore.html#QSemaphore(int)&quot;&gt;&lt;tt&gt;QSemaphore&lt;/tt&gt;&lt;/a&gt; to solve that problem.&lt;/p&gt;
&lt;p&gt;A non-computing example of a semaphore would be dining at a restaurant. A semaphore is initialized with the number of chairs in the restaurant. As people arrive, they want a seat. As seats are filled, &lt;a href=&quot;QSemaphore.html#available()&quot;&gt;&lt;tt&gt;available&lt;/tt&gt;&lt;/a&gt; is decremented. As people leave, the &lt;a href=&quot;QSemaphore.html#available()&quot;&gt;&lt;tt&gt;available&lt;/tt&gt;&lt;/a&gt; is incremented, allowing more people to enter. If a party of 10 people want to be seated, but there are only 9 seats, those 10 people will wait, but a party of 4 people would be seated (taking the available seats to 5, making the party of 10 people wait longer).&lt;/p&gt;

@see &lt;a href=&quot;QMutex.html&quot;&gt;&lt;tt&gt;QMutex&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QWaitCondition.html&quot;&gt;&lt;tt&gt;QWaitCondition&lt;/tt&gt;&lt;/a&gt;
@see &lt;tt&gt;QThread&lt;/tt&gt;
@see Semaphores Example&lt;/tt&gt; */">
    <method name="public QSemaphore(int n)" doc="/**
&lt;p&gt;Creates a new semaphore and initializes the number of resources it guards to &lt;tt&gt;n&lt;/tt&gt; (by default, 0).&lt;/p&gt;

@see &lt;a href=&quot;QSemaphore.html#release(int)&quot;&gt;&lt;tt&gt;release&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QSemaphore.html#available()&quot;&gt;&lt;tt&gt;available&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="public QSemaphore()" doc="/**
&lt;p&gt;Equivalent to &lt;a href=&quot;QSemaphore.html#QSemaphore(int)&quot;&gt;&lt;tt&gt;QSemaphore&lt;/tt&gt;&lt;/a&gt;(0). */"/>
    <method name="public final void acquire(int n)" doc="/**
&lt;p&gt;Tries to acquire &lt;tt&gt;n&lt;/tt&gt; resources guarded by the semaphore. If &lt;tt&gt;n&lt;/tt&gt; &amp;gt; &lt;a href=&quot;QSemaphore.html#available()&quot;&gt;&lt;tt&gt;available&lt;/tt&gt;&lt;/a&gt;, this call will block until enough resources are available.&lt;/p&gt;

@see &lt;a href=&quot;QSemaphore.html#release(int)&quot;&gt;&lt;tt&gt;release&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QSemaphore.html#available()&quot;&gt;&lt;tt&gt;available&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QSemaphore.html#tryAcquire(int, int)&quot;&gt;&lt;tt&gt;tryAcquire&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="public final void acquire()" doc="/**
&lt;p&gt;Equivalent to &lt;a href=&quot;QSemaphore.html#acquire(int)&quot;&gt;acquire&lt;/tt&gt;&lt;/a&gt;(1). */"/>
    <method name="public final int available()" doc="/**
&lt;p&gt;Returns the number of resources currently available to the semaphore. This number can never be negative.&lt;/p&gt;

@see &lt;a href=&quot;QSemaphore.html#acquire(int)&quot;&gt;&lt;tt&gt;acquire&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QSemaphore.html#release(int)&quot;&gt;&lt;tt&gt;release&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="public final void release(int n)" doc="/**
&lt;p&gt;Releases &lt;tt&gt;n&lt;/tt&gt; resources guarded by the semaphore.&lt;/p&gt;
&lt;p&gt;This function can be used to &amp;quot;create&amp;quot; resources as well. For example:&lt;/p&gt;
&lt;pre&gt;    QSemaphore sem(5);      &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; a semaphore that guards 5 resources
    sem.acquire(5);         &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; acquire all 5 resources
    sem.release(5);         &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; release the 5 resources
    sem.release(10);        &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; &amp;quot;create&amp;quot; 10 new resources&lt;/pre&gt;

@see &lt;a href=&quot;QSemaphore.html#acquire(int)&quot;&gt;&lt;tt&gt;acquire&lt;/tt&gt;&lt;/a&gt;
@see &lt;a href=&quot;QSemaphore.html#available()&quot;&gt;&lt;tt&gt;available&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="public final void release()" doc="/**
&lt;p&gt;Equivalent to &lt;a href=&quot;QSemaphore.html#release(int)&quot;&gt;release&lt;/tt&gt;&lt;/a&gt;(1). */"/>
    <method name="public final boolean tryAcquire(int n)" doc="/**
&lt;p&gt;Tries to acquire &lt;tt&gt;n&lt;/tt&gt; resources guarded by the semaphore and returns true on success. If &lt;a href=&quot;QSemaphore.html#available()&quot;&gt;&lt;tt&gt;available&lt;/tt&gt;&lt;/a&gt; &amp;lt; &lt;tt&gt;n&lt;/tt&gt;, this call immediately returns false without acquiring any resources.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;    QSemaphore sem(5);      &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 5
    sem.tryAcquire(250);    &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 5, returns false
    sem.tryAcquire(3);      &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 2, returns true&lt;/pre&gt;

@see &lt;a href=&quot;QSemaphore.html#acquire(int)&quot;&gt;&lt;tt&gt;acquire&lt;/tt&gt;&lt;/a&gt; */"/>
    <method name="public final boolean tryAcquire()" doc="/**
&lt;p&gt;Equivalent to &lt;a href=&quot;QSemaphore.html#tryAcquire(int, int)&quot;&gt;&lt;tt&gt;tryAcquire&lt;/tt&gt;&lt;/a&gt;(1). */"/>
    <method name="public final boolean tryAcquire(int n, int timeout)" doc="/**
&lt;p&gt;Tries to acquire &lt;tt&gt;n&lt;/tt&gt; resources guarded by the semaphore and returns true on success. If &lt;a href=&quot;QSemaphore.html#available()&quot;&gt;&lt;tt&gt;available&lt;/tt&gt;&lt;/a&gt; &amp;lt; &lt;tt&gt;n&lt;/tt&gt;, this call will wait for at most &lt;tt&gt;timeout&lt;/tt&gt; milliseconds for resources to become available.&lt;/p&gt;
&lt;p&gt;Note: Passing a negative number as the &lt;tt&gt;timeout&lt;/tt&gt; is equivalent to calling &lt;a href=&quot;QSemaphore.html#acquire(int)&quot;&gt;&lt;tt&gt;acquire&lt;/tt&gt;&lt;/a&gt;, i.e&amp;#x2e; this function will wait forever for resources to become available if &lt;tt&gt;timeout&lt;/tt&gt; is negative.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;    QSemaphore sem(5);            &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 5
    sem.tryAcquire(250, 1000);    &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 5, waits 1000 milliseconds and returns false
    sem.tryAcquire(3, 30000);     &lt;span class=&quot;comment&quot;&gt;//&lt;/span&gt; sem.available() == 2, returns true without waiting&lt;/pre&gt;

@see &lt;a href=&quot;QSemaphore.html#acquire(int)&quot;&gt;&lt;tt&gt;acquire&lt;/tt&gt;&lt;/a&gt; */"/>
</class>
