NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/38554: kernel condvar wait functions should take an absolute timeout

>Number:         38554
>Category:       kern
>Synopsis:       kernel condvar wait functions should take an absolute timeout
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu May 01 11:50:00 +0000 2008
>Originator:     Andrew Doran
>Release:        4.99.62
The NetBSD Project
When sleeping on condition variables in the kernel, threads must be
prepared to handle "spurious wakeups": wakeups that occur due to some
external agent and do not signal an event of interest to the sleeping 

We have lots of code segments that do, for example:

  while (!condition) {
     error = cv_timedwait(&cv, &lock, hz);
     if (error == EWOULDBLOCK)

If a spurious wakeup occurs, the thread could sleep for N*hz instead
of hz, or it could awaken early and return. Early wakeups are bad news 
for syscalls like nanosleep().
Code inspection.

Make condvars take an absolute timeout and add some simple functions
to help with computing wakeup times. The above code fragment would
then look something like the following:

  when = cv_time_now() + cv_time_second();
  while (!condition) {
     error = cv_timedwait(&cv, &lock, when);
     if (error == EWOULDBLOCK)

This makes condvars slightly more compatible with the Solaris
interfaces. I think it should also be done before 5.0, because
it's a fairly major change to the interface and it would be good
to have it full stable before it is set in stone.

Home | Main Index | Thread Index | Old Index