• Post Reply Bookmark Topic Watch Topic
  • New Topic

spurious wakeup in java

 
radha gogia
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I get the basic concept of spurious wake-up in java or any other link from where I can understand the entire mechanism clearly.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's one previous discussion http://www.coderanch.com/t/234023/threads/java/spurious-wakeup
 
Henry Wong
author
Sheriff
Posts: 22542
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
radha gogia wrote:Can I get the basic concept of spurious wake-up in java or any other link from where I can understand the entire mechanism clearly.


I don't think that "spurious wake ups" can even be considered a java mechanism. Or even a mechanism, it is just a behavior. Many Operating Systems threading systems have spurious wake ups, and since most (if not all, now) JVMs use the underlying threading environment, then Java must also allow for the possible behavior.

As for why it happens, take Unix for example. You can send signals to an application, which wakes up an application. Most of the time, the signal is a SIGKILL, and the application exits. Other times, it could be a different signal, which the application processes, and goes back to what it was doing.

Anyway, it was found to be a race condition between condition variables and signals. It was possible for condition variables to lose its notification, while a signal was happening. Of course, this is a bug, and of course, it can be fixed. However, how often do a condition variable clash with signals? How often do users even send signals? How complicated is it to fix this bug? And how much latency will the library take, by converting two relatively simple mechanisms, into one big complicated mechanism?

So, it was just better, to just have the condition variable wake up on signal, and modify the documentation, to say that spurious wake ups can happen.

Hope this helps,
Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!