Topic: Sleep function use in testing thread coperation for our embedded ruby.

We are testing thread coperation for our embedded ruby. We have a C ruby extension implementented the following methods
1. longRunningMethod()
2. shortRunningMethod().


Here is a code for the checking the thread cooperation


//file
test.rb


require 'mymodule'

$a = 0;
obj = MyModule::MyClass.new
t1 = Thread.new{$a = obj.veryLongRunningOperation(); puts"doneLong"}
sleep 1
$a = obj.shortOperation()
puts "doneShort"
t1.join


We have ensured that the longRunningMethod takes more than 1sec(5sec) for execution using nested for loops
As per our understanding, the shortRunningMethod should be completed first and then longRunningMethod.

However we observed this only when we did not have any sleep command.
But when we introduced the "sleep 1" statement. The longRunningMethod gets executed first and then shortRunningMethod

Anyone would give us the pointers as to why the sleep statement produces this result?

We are using ruby 1.8.6

Last edited by salunke09 (2011-09-05 13:48:21)