1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* thread.c (rb_mutex_sleep): fix to allow spurious wakeup.

* NEWS: write about spurious wakeup.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2012-11-28 14:40:00 +00:00
parent e59c7307da
commit 09f9aa4385
3 changed files with 13 additions and 3 deletions

View file

@ -1,3 +1,9 @@
Wed Nov 28 23:39:01 2012 Koichi Sasada <ko1@atdot.net>
* thread.c (rb_mutex_sleep): fix to allow spurious wakeup.
* NEWS: write about spurious wakeup.
Wed Nov 28 23:37:14 2012 Masaya Tarui <tarui@ruby-lang.org> Wed Nov 28 23:37:14 2012 Masaya Tarui <tarui@ruby-lang.org>
* NEWS (Thread) remove incompatible changes. * NEWS (Thread) remove incompatible changes.

1
NEWS
View file

@ -116,6 +116,7 @@ with all sufficient information, see the ChangeLog file.
* Mutex#lock, Mutex#unlock, Mutex#try_lock, Mutex#synchronize * Mutex#lock, Mutex#unlock, Mutex#try_lock, Mutex#synchronize
and Mutex#sleep are no longer allowed to be used from trap handler and Mutex#sleep are no longer allowed to be used from trap handler
and raise a ThreadError in such case. and raise a ThreadError in such case.
* Mutex#sleep may spurious wakeup. Check after wakeup.
* NilClass * NilClass
* added method: * added method:

View file

@ -4294,15 +4294,15 @@ rb_mutex_abandon_all(rb_mutex_t *mutexes)
static VALUE static VALUE
rb_mutex_sleep_forever(VALUE time) rb_mutex_sleep_forever(VALUE time)
{ {
rb_thread_sleep_deadly(); sleep_forever(GET_THREAD(), 1, 0); /* permit spurious check */
return Qnil; return Qnil;
} }
static VALUE static VALUE
rb_mutex_wait_for(VALUE time) rb_mutex_wait_for(VALUE time)
{ {
const struct timeval *t = (struct timeval *)time; struct timeval *t = (struct timeval *)time;
rb_thread_wait_for(*t); sleep_timeval(GET_THREAD(), *t, 0); /* permit spurious check */
return Qnil; return Qnil;
} }
@ -4334,6 +4334,9 @@ rb_mutex_sleep(VALUE self, VALUE timeout)
* Releases the lock and sleeps +timeout+ seconds if it is given and * Releases the lock and sleeps +timeout+ seconds if it is given and
* non-nil or forever. Raises +ThreadError+ if +mutex+ wasn't locked by * non-nil or forever. Raises +ThreadError+ if +mutex+ wasn't locked by
* the current thread. * the current thread.
*
* Note that this method can wakeup without explicit Thread#wakeup call.
* For example, receiving signal and so on.
*/ */
static VALUE static VALUE
mutex_sleep(int argc, VALUE *argv, VALUE self) mutex_sleep(int argc, VALUE *argv, VALUE self)