A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Thread/Standard_Library/Mutex below:

Ruby Programming/Reference/Objects/Thread/Standard Library/Mutex - Wikibooks, open books for an open world

From Wikibooks, open books for an open world

The Mutex class (loadable via require 'thread') is a way of guaranteeing concurrency for a specific block.

You can time out a wait like this in 1.9.2 (or jruby)

require 'thread'
a = Mutex.new
b = ConditionVariable.new
a.synchronize {
 a.wait(b, 3) # timeout after 3 secs
}

In 1.8 non jruby, you can use the timeout library, like

require 'thread'
require 'timeout'
a = Mutex.new
b = ConditionVariable.new

begin
Timeout::timeout(3) {
  a.synchronize {
    a.wait(b)
  }
}
rescue Timeout::Error
 # timed out
end

a tutorial


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4