Class | ConditionVariable |
In: |
ext/fastthread/fastthread.c
ext/fastthread/fastthread.c |
Parent: | Object |
ConditionVariable objects augment class Mutex. Using condition variables, it is possible to suspend while in the middle of a critical section until a resource becomes available.
Example:
require 'thread' mutex = Mutex.new resource = ConditionVariable.new a = Thread.new { mutex.synchronize { # Thread 'a' now needs the resource resource.wait(mutex) # 'a' can now have the resource } } b = Thread.new { mutex.synchronize { # Thread 'b' has finished using the resource resource.signal } }
Wakes up all threads waiting for this condition.
/* * Document-method: broadcast * call-seq: broadcast * * Wakes up all threads waiting for this condition. * */ static VALUE rb_condvar_broadcast(VALUE self) { ConditionVariable *condvar; Data_Get_Struct(self, ConditionVariable, condvar); thread_exclusive(wake_all, (VALUE)&condvar->waiting); rb_thread_schedule(); return self; }
Wakes up all threads waiting for this condition.
/* * Document-method: broadcast * call-seq: broadcast * * Wakes up all threads waiting for this condition. * */ static VALUE rb_condvar_broadcast(VALUE self) { ConditionVariable *condvar; Data_Get_Struct(self, ConditionVariable, condvar); thread_exclusive(wake_all, (VALUE)&condvar->waiting); rb_thread_schedule(); return self; }
for marshalling mutexes and condvars
/* for marshalling mutexes and condvars */ static VALUE dummy_load(VALUE self, VALUE string) { return Qnil; }