Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Q3Semaphore Class Reference

The Q3Semaphore class provides a robust integer semaphore. More...

 #include <Q3Semaphore>

This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code. See Porting to Qt 4 for more information.

Note: All functions in this class are thread-safe.

Public Functions

Q3Semaphore ( int maxcount )
virtual ~Q3Semaphore ()
int available () const
int total () const
bool tryAccess ( int n )
int operator++ ( int )
int operator+= ( int n )
int operator-- ( int )
int operator-= ( int n )

Detailed Description

The Q3Semaphore class provides a robust integer semaphore.

A Q3Semaphore can be used to serialize thread execution, in a similar way to a QMutex. A semaphore differs from a mutex, in that a semaphore can be accessed by more than one thread at a time.

For example, suppose we have an application that stores data in a large tree structure. The application creates 10 threads (commonly called a thread pool) to perform searches on the tree. When the application searches the tree for some piece of data, it uses one thread per base node to do the searching. A semaphore could be used to make sure that two threads don't try to search the same branch of the tree at the same time.

A non-computing example of a semaphore would be dining at a restaurant. A semaphore is initialized to have a maximum count equal to the number of chairs in the restaurant. As people arrive, they want a seat. As seats are filled, the semaphore is accessed, once per person. As people leave, the access is released, 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).

When a semaphore is created it is given a number which is the maximum number of concurrent accesses it will permit. This amount may be changed using operator++(), operator--(), operator+=() and operator-=(). The number of accesses allowed is retrieved with available(), and the total number with total(). Note that the incrementing functions will block if there aren't enough available accesses. Use tryAccess() if you want to acquire accesses without blocking.

Member Function Documentation

Q3Semaphore::Q3Semaphore ( int maxcount )

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

Q3Semaphore::~Q3Semaphore () [virtual]

Destroys the semaphore.

Warning: If you destroy a semaphore that has accesses in use the resultant behavior is undefined.

int Q3Semaphore::available () const

Returns the number of accesses currently available to the semaphore.

int Q3Semaphore::total () const

Returns the total number of accesses to the semaphore.

bool Q3Semaphore::tryAccess ( int n )

Try to get access to the semaphore. If available() < n, this function will return false immediately. If available() >= n, this function will take n accesses and return true. This function does not block.

int Q3Semaphore::operator++ ( int )

Postfix ++ operator.

Try to get access to the semaphore. If available() == 0, this call will block until it can get access, i.e. until available() > 0.

int Q3Semaphore::operator+= ( int n )

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

int Q3Semaphore::operator-- ( int )

Postfix -- operator.

Release access of the semaphore. This wakes all threads waiting for access to the semaphore.

int Q3Semaphore::operator-= ( int n )

Release n accesses to the semaphore.

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.8
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web