A
A
andll2013-02-18 11:55:55
Java
andll, 2013-02-18 11:55:55

Spurious wakeup simulation

Question - how to write a test that demonstrates spurious wakeup under debian (or windows) using oracle jre 6?
A search on the subject yielded this thread:
stackoverflow.com/questions/6700917/forcing-a-spurious-wake-up-in-java
Which completely describes my question, and in which, alas, there is no answer to it.
Yes, signals and truth (at least with sun java in debian) don't result in a spurious wakeup.
PS No need to copy the most popular answer from the link, talking about the "accidental" notify ()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gvsmirnov, 2013-02-18
@gvsmirnov

If you read the OpenJDK sources, you can find out what waitleads to thread parking using os::PlatformEvent::park. For src/os/linux/vm/os_linux.cppinside them there is a cycle of the form

while (_Event < 0) {
    status = os::Linux::safe_cond_timedwait(_cond, _mutex, &abst);
    //...
}

Moreover _Event, only the method call can change unpark.
However, with timed wait, there is this line in the loop:
if (!FilterSpuriousWakeups) break ;

Try using a long timed wait and signaling the process by setting java -XX:-FilterSpuriousWakeups. The description of the option says that it is valid only for Solaris, but judging by the code, this is not the case.
There is no way to try it yourself right now, so this is just a theoretical assumption.
PS Why do you need to simulate them?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question