ruby condition variables

Added a few puts to show how condition variable works:

require 'thread'

mutex = Mutex.new
resource = ConditionVariable.new

a = Thread.new {
  mutex.synchronize {
    puts "a waiting"
    puts "a has it"

b = Thread.new {
  mutex.synchronize {
    puts "b executing"
    puts "b finished"


The output produced is:

a waiting
b executing
b finished
a has it


0 Responses to “ruby condition variables”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog Stats

  • 228,119 hits

%d bloggers like this: