Class: XThread::RBMonitorMixin::RBConditionVariable

Inherits:
Object
  • Object
show all
Defined in:
lib/xthread/monitor.rb

Overview

FIXME: This isn’t documented in Nutshell.

Since MonitorMixin.new_cond returns a ConditionVariable, and the example above calls while_wait and signal, this class should be documented.

Defined Under Namespace

Classes: Timeout

Instance Method Summary collapse

Instance Method Details

#broadcastObject

Wakes up all threads waiting for this lock.



140
141
142
143
# File 'lib/xthread/monitor.rb', line 140

def broadcast
	@monitor.__send__(:mon_check_owner)
	@cond.broadcast
end

#signalObject

Wakes up the first thread in line waiting for this lock.



132
133
134
135
# File 'lib/xthread/monitor.rb', line 132

def signal
	@monitor.__send__(:mon_check_owner)
	@cond.signal
end

#wait(timeout = nil) ⇒ Object

Releases the lock held in the associated monitor and waits; reacquires the lock on wakeup.

If timeout is given, this method returns after timeout seconds passed, even if no other thread doesn’t signal.



100
101
102
103
104
105
106
107
108
109
# File 'lib/xthread/monitor.rb', line 100

def wait(timeout = nil)
	@monitor.__send__(:mon_check_owner)
	count = @monitor.__send__(:mon_exit_for_cond)
	begin
	  @cond.wait(@monitor.instance_variable_get("@mon_mutex"), timeout)
	  return true
	ensure
	  @monitor.__send__(:mon_enter_for_cond, count)
	end
end

#wait_untilObject

Calls wait repeatedly until the given block yields a truthy value.



123
124
125
126
127
# File 'lib/xthread/monitor.rb', line 123

def wait_until
	until yield
	  wait
	end
end

#wait_whileObject

Calls wait repeatedly while the given block yields a truthy value.



114
115
116
117
118
# File 'lib/xthread/monitor.rb', line 114

def wait_while
	while yield
	  wait
	end
end