Thread fun
By Gentle Hornbill, 3 Days ago, written in ruby.class Foo
def initialize
@a = 3
@b = 2
end
def m1
@a = @b - 1
end
def m2
@b = @a + 2
end
def to_s
"(#{@a}, #{@b})"
end
end
$foo = Foo.new
# Create the two threads
t1 = Thread.new {$foo.m1}
t2 = Thread.new {$foo.m2}
# Waits for the threads to stop
t1.join
t2.join
# Print out the result
print $foo.to_s
exit
