Skip to content

Instantly share code, notes, and snippets.

@zhengjia
Created May 12, 2012 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhengjia/2664048 to your computer and use it in GitHub Desktop.
Save zhengjia/2664048 to your computer and use it in GitHub Desktop.
variable and thread
require 'thread'
@value = 1
@cond = ConditionVariable.new
@mutex = Mutex.new
t = Thread.new do
value = @value
@mutex.synchronize do
while true
STDOUT.puts value
@cond.wait @mutex
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment