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  ·  Classes  ·  Annotées  ·  Hiérarchie  ·  Fonctions  ·  Structure  · 

QSemaphore Class Reference


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

#include <qthread.h>

Inherits Qt.

List of all member functions.

Public Members


Detailed Description

The QSemaphore class provides a robust integer semaphore.

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

An example would be an application that stores data in a large tree structure. The application creates 10 threads (commonly called a thread pool) to do 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 2 threads don't try to search the same branch of the tree.

A real world example of a semaphore would be dining at a restuarant. A semaphore initialized to have a maximum count equal to the number of chairs in the restuarant. 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).


Member Function Documentation

QSemaphore::QSemaphore ( int maxcount )

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

QSemaphore::~QSemaphore () [virtual]

Destroys the semaphore.

int QSemaphore::available () const

This function returns the number of accesses currently available to the semaphore.

int QSemaphore::operator++ ( int )

Postfix ++ operator.

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

int QSemaphore::operator+= ( int n )

Try to get access to the semaphore. If available() is >= total(), the calling thread blocks until it can get access. The calling will only get access from the semaphore if it can get all n accesses at once.

int QSemaphore::operator-- ( int )

Postfix -- operator.

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

int QSemaphore::operator-= ( int n )

Release n accesses to the semaphore.

int QSemaphore::total () const

This function returns the total number of accesses to the semaphore.


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2005 Trolltech, all rights reserved.

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 2.3
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