📄 qsemaphore.3qt
字号:
'\" t.TH QSemaphore 3qt "24 January 2005" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQSemaphore \- Robust integer semaphore.br.PP\fC#include <qthread.h>\fR.PPInherits Qt..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQSemaphore\fR ( int ) ".br.ti -1c.BI "virtual \fB~QSemaphore\fR () ".br.ti -1c.BI "int \fBavailable\fR () const".br.ti -1c.BI "int \fBtotal\fR () const".br.ti -1c.BI "int \fBoperator++\fR ( int ) ".br.ti -1c.BI "int \fBoperator--\fR ( int ) ".br.ti -1c.BI "int \fBoperator+=\fR ( int ) ".br.ti -1c.BI "int \fBoperator-=\fR ( int ) ".br.in -1c.SH DESCRIPTIONThe QSemaphore class provides a robust integer semaphore..PPQSemaphore 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..PPAn 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..PPA 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)..SH MEMBER FUNCTION DOCUMENTATION.SH "QSemaphore::QSemaphore ( int maxcount )"Creates a new semaphore. The semaphore can be concurrently accessed at most \fImaxcount\fR times..SH "QSemaphore::~QSemaphore () \fC[virtual]\fR"Destroys the semaphore..SH "int QSemaphore::available () const"This function returns the number of accesses currently available to the semaphore..SH "int QSemaphore::operator++ ( int )"Postfix ++ operator..PPTry to get access to the semaphore. If available() is >= total(), this call will block until it can get access..SH "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 \fIn\fR accesses at once..SH "int QSemaphore::operator-- ( int )"Postfix -- operator..PPRelease access of the semaphore. This wakes all threads waiting for access to the semaphore..SH "int QSemaphore::operator-= ( int n )"Release \fIn\fR accesses to the semaphore..SH "int QSemaphore::total () const"This function returns the total number of accesses to the semaphore..SH "SEE ALSO".BR http://doc.trolltech.com/qsemaphore.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports make our job much simpler. Thank you..PIn case of content or formattting problems with this manual page, pleasereport them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qsemaphore.3qt) and the Qtversion (2.3.10).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -