请输入您要查询的百科知识:

 

词条 Spurious wakeup
释义

  1. External links

{{Disputed|date=May 2018}}{{Citation style|date=September 2009}}Spurious wakeup describes a complication in the use of condition variables as provided by certain multithreading APIs such as POSIX Threads and the Windows API.

Even after a condition variable appears to have been signaled from a waiting thread's point of view, the condition that was awaited may still be false. One of the reasons for this is a spurious wakeup; that is, a thread might be awoken from its waiting state even though no thread signaled the condition variable. For correctness it is necessary, then, to verify that the condition is indeed true after the thread has finished waiting. Because spurious wakeup can happen repeatedly, this is achieved by waiting inside a loop that terminates when the condition is true, for example:

/* In any waiting thread: */

while(!buf->full)

wait(&buf->cond, &buf->lock);

/* In any other thread: */

if(buf->n >= buf->size){

buf->full = 1;

signal(&buf->cond);

}

In this example it is known that another thread will set buf->full (the actual condition awaited) before signaling buf->cond (the means of synchronizing the two threads). The waiting thread will always verify the truth of the actual condition upon returning from wait, ensuring correct behaviour if spurious wakeup occurs.

According to David R. Butenhof's Programming with POSIX Threads {{ISBN|0-201-63392-2}}:

"This means that when you wait on a condition variable, the wait may (occasionally) return when no thread specifically broadcast or signaled that condition variable. Spurious wakeups may sound strange, but on some multiprocessor systems, making condition wakeup completely predictable might substantially slow all condition variable operations. The race conditions that cause spurious wakeups should be considered rare."

External links

  • {{webarchive |url=https://web.archive.org/web/20040822013855/http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-Q2DPC-TKT1_html/thrd0124.html |date=August 22, 2004 |title=pthread_cond_wait }}
  • {{cite web

| url=http://zthread.sourceforge.net/html/classZThread_1_1Condition.html
| title=ZThreads: Condition Class Reference
| author=Eric Crahen
| quote=A Condition is not subject to spurious wakeup.
| date=2003-07-16}}
  • {{cite web

| url=http://blog.vladimirprus.com/2005/07/spurious-wakeups.html
| title= Spurious wakeups
| author=Vladimir Prus
| date=2005-07-06}}
  • {{cite web

| url=http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html
| title=pthread_cond_timedwait, pthread_cond_wait - wait on a condition
| website=Single UNIX Specification
| publisher=The Open Group
| date=2013}}
  • {{cite web

| url=https://msdn.microsoft.com/en-us/library/ms686301%28v=vs.85%29.aspx
| title=SleepConditionVariableCS function
| publisher=MSDN
| date=2016-07-15}}
  • {{cite web

| url=https://blogs.msdn.microsoft.com/oldnewthing/20180201-00/?p=97946
| title=Spurious wake-ups in Win32 condition variables
| author=Raymond Chen
| date=2018-02-01}}
  • {{Javadoc:SE|java/util/concurrent/locks|Condition}} (Java Platform SE)
{{DEFAULTSORT:Spurious Wakeup}}

2 : C POSIX library|Threads (computing)

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/11 23:31:51