Skip to content

Instantly share code, notes, and snippets.

@zhengjia
Created May 12, 2012 04:01
Show Gist options
  • Save zhengjia/2664048 to your computer and use it in GitHub Desktop.
Save zhengjia/2664048 to your computer and use it in GitHub Desktop.

Revisions

  1. zhengjia revised this gist May 14, 2012. 2 changed files with 0 additions and 13 deletions.
    File renamed without changes.
    13 changes: 0 additions & 13 deletions instance variable
    Original file line number Diff line number Diff line change
    @@ -1,13 +0,0 @@
    require 'thread'

    @value = 1
    @cond = ConditionVariable.new
    @mutex = Mutex.new
    t = Thread.new do
    @mutex.synchronize do
    while true
    STDOUT.puts @value
    @cond.wait @mutex
    end
    end
    end
  2. zhengjia revised this gist May 12, 2012. 2 changed files with 14 additions and 0 deletions.
    File renamed without changes.
    14 changes: 14 additions & 0 deletions local variable
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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
  3. zhengjia created this gist May 12, 2012.
    13 changes: 13 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    require 'thread'

    @value = 1
    @cond = ConditionVariable.new
    @mutex = Mutex.new
    t = Thread.new do
    @mutex.synchronize do
    while true
    STDOUT.puts @value
    @cond.wait @mutex
    end
    end
    end