A
Armin Armbruster
Hi,
I've tried the sample code below on Ubuntu (7.04) as well as on a
Windows XP machine.
While under Linux I get the expected result, namely task 1 counting
away, under XP task 1 stalls until I enter something, then runs one loop
and stalls again.
I would have thought that the call to gets in task 2 only blocks task 2,
but not task 1.
Can anybody please explain this to me and more importantly show me a
solution on how to do this so it works under Windows as well?
Thanks in advance,
Armin
require 'thread'
t1 = Thread.new{
count = 0
loop{
count += 1
sleep 1
print "T1: #{count}\n"
}
}
t2 = Thread.new{
loop{
a = gets
print " T2: a = #{a}\n"
}
}
t1.join
t2.join
I've tried the sample code below on Ubuntu (7.04) as well as on a
Windows XP machine.
While under Linux I get the expected result, namely task 1 counting
away, under XP task 1 stalls until I enter something, then runs one loop
and stalls again.
I would have thought that the call to gets in task 2 only blocks task 2,
but not task 1.
Can anybody please explain this to me and more importantly show me a
solution on how to do this so it works under Windows as well?
Thanks in advance,
Armin
require 'thread'
t1 = Thread.new{
count = 0
loop{
count += 1
sleep 1
print "T1: #{count}\n"
}
}
t2 = Thread.new{
loop{
a = gets
print " T2: a = #{a}\n"
}
}
t1.join
t2.join