Condition Variables 编辑
This chapter describes the API for creating and destroying condition variables, notifying condition variables of changes in monitored data, and making a thread wait on such notification.
Conditions are closely associated with a single monitor, which typically consists of a mutex, one or more condition variables, and the monitored data. The association between a condition and a monitor is established when a condition variable is created, and the association persists for its life. In addition, a static association exists between the condition and some data within the monitor. This data is what will be manipulated by the program under the protection of the monitor.
A call to /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_WaitCondVar
causes a thread to block until a specified condition variable receives notification of a change of state in its associated monitored data. Other threads may notify the condition variable when changes occur.
For an introduction to NSPR thread synchronization, including locks and condition variables, see Introduction to NSPR.
For reference information on NSPR locks, see Locks.
NSPR provides a special type, /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRMonitor
, for use with Java. Unlike a mutex of type /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRLock
, which can have multiple associated condition variables of type /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRCondVar
, a mutex of type /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRMonitor
has a single, implicitly associated condition variable. For information about /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRMonitor
, see /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/Monitors.
Condition Variable Type
Condition Variable Functions
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_NewCondVar
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_DestroyCondVar
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_WaitCondVar
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_NotifyCondVar
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_NotifyAllCondVar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论