Questions tagged [spurious-wakeup]
19 questions
220
votes
7 answers
Do spurious wakeups in Java actually happen?
Seeing various locking related question and (almost) always finding the 'loop because of spurious wakeups' terms1 I wonder, has anyone experienced such kind of a wakeup (assuming a decent hardware/software environment for example)?
I know the term…

akarnokd
- 69,132
- 14
- 157
- 192
11
votes
5 answers
How does condition_variable::wait_for() deal with spurious wakeups?
Spurious wakup is allowed by various platforms. To counter that, we write below looping mechanism:
while(ContinueWaiting())
cv.wait(lock); // cv is a `std::conditional_variable` object
Same thing is understandable for…

iammilind
- 68,093
- 33
- 169
- 336
8
votes
3 answers
When can std::condition_variable be used without a predicate?
If std::condition_variable can be signaled due to the spurious wakeups (and we can't be sure that the condition we need is really satisfied), why do C++ Standard Library provide the overloads of wait() method without a predicate? What are the…

undermind
- 1,779
- 13
- 33
6
votes
0 answers
Does the threading.Event() object suffer from spurious wakeup?
In C, pthread condition variables serve the same purpose as threading.Event() variables in python. My question is, do threading.Event() variables suffer from the same spurious wakeup issues as pthread condition variables?

Zachary Oldham
- 838
- 1
- 5
- 21
4
votes
2 answers
What's the correct way to deal with spurious wakeups, in general?
Among the options below, is there any correct way to deal with spurious wakeups when using conditional variables?
1) Put the wait(unique_lock_ul) into an infinite while loop, using a boolean
unique_lock ul(m);
while(!full)
…

ImAUser
- 119
- 1
- 9
4
votes
2 answers
Unexpected thread wakeup
I was expecting the second thread in the following example to hang, since it waits on an object with no corresponding notify. Instead, it falls through to the println, presumably due to a spurious wakeup.
public class Spurious {
public static…

Marco
- 479
- 4
- 10
2
votes
1 answer
c++11 std::notify_all and spurious wakeup
with c++11.
As std::notify_all would cause spurious wakeup, then why std::notify_all is remained but not std::notify_one all the time?
And could std::notify_one cause spurious wakeup by the way?
elaborating my doubts:
When I call…

f1msch
- 509
- 2
- 12
1
vote
1 answer
How could tell which way is condition_variable.wait_for unblocked by, spurious wakeup or cv_status::timeout?
As far as I know, only condition_variable.wait_for with predicate(because double check inside) could avoid to be unblocked by spurious wakeup, but not the version without predicate(use if not while).
But what if I want to do something when only…

f1msch
- 509
- 2
- 12
1
vote
2 answers
Does a spurious wake up unblock all waiting threads, even the unrelated ones?
I'm still new to multi-threading in C++ and I'm currently trying to wrap my head around "spurious wake-ups" and what's causing them. I've done some digging on condition variables, kernel signals, futex, etc., and found several culprits on why and…

Constantinos Glynos
- 2,952
- 2
- 14
- 32
1
vote
1 answer
Are spurios wakeups accompanied by an InterruptedException?
The javadoc for Object.wait mentions,
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop.
synchronized (obj) {
while () {
…

second
- 4,069
- 2
- 9
- 24
1
vote
1 answer
Spurious wake-up of WaitOne() in C#
There are two CRITERIA in my program which decides whether a thread should wait or continue.
First Criterion: Change in an XML file. I have a file watcher which sets an AutoResetEvent (_waitTillXmlChanges.Set()) if the XML file changes and hence…

skm
- 5,015
- 8
- 43
- 104
0
votes
1 answer
Why I can't check spurious wakeup by if condition instead of while loop
I'm currently reading Java The Complete Reference book, multithread section.
There is an example about handling spurious wakeup.
It's the classic producer-consumer example that I bring get() method here:
synchronized int get() {
…

Mehdi Rahimi
- 1,453
- 5
- 20
- 31
0
votes
1 answer
Spurious wake-up and safety property
In mutual exclusion, we should satisfy the safety and progress properties. However, if we have a spurious wake-ups, is the safety property still satisfied?

Ann
- 11
- 2
0
votes
1 answer
Is there a good way to distinguish spurious wake up and Thread.interrupt()?
I want to make a thread which can be interrupted at any time while be guarded against spurious wake ups.
The problem here is that both spurious wakes as well as interrupts work the same: they throw InterruptedException
void anyMethodCalledByThread()…

Nexen
- 1,663
- 4
- 16
- 44
0
votes
2 answers
how to avoid spurious wakeup without a predicate?
I have a thread lets call it t1, that periodically sends something after x seconds.
This "x seconds part" can be changed from other thread (t2).
I am supposed to be able to do following from thread t1.
wait for "x seconds" and then send…

VK13
- 1
- 3