# Thread synchronization

**URL:** <https://www.ruby-forum.com/t/thread-synchronization/120254>\
**Category:** Ruby\
**Created:** [November 15, 2007, 10:38am UTC](https://www.ruby-forum.com/t/thread-synchronization/120254 "2007-11-15T10:38:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sirtyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@sirtyman](https://www.ruby-forum.com/u/sirtyman)\
**Post date:** [November 15, 2007, 10:38am UTC](https://www.ruby-forum.com/t/thread-synchronization/120254/1 "2007-11-15T10:38:23Z")

</div>

Hi guys,  
I’ve got issue with this example part of code:  
stationStatsTr = Thread.new do  
while(true)  
puts “stationStatsTr\n”  
sleep 1  
end  
end

rulesTr = Thread.new do  
while(true)  
#puts stationStatsTr.status  
sleep 1  
stationStatsTr.stop() if stationStatsTr.status == “run”  
puts “rulesTr\n”  
sleep 1  
end  
end

stationStatsTr.join(10)  
rulesTr.join(10)

#the output from this is as follows  
stationStatsTr  
stationStatsTr  
stationStatsTr  
stationStatsTr  
stationStatsTr  
stationStatsTr  
stationStatsTr  
stationStatsTr  
stationStatsTr  
stationStatsTr  
C:/Documents and  
Settings/PROXIMETRY/Desktop/Autotests/Fake\_DDL/testing.rb:12: undefined  
method `stop' for #<Thread:0x2bb79dc dead> (NoMethodError) from C:/Documents and Settings/PROXIMETRY/Desktop/Autotests/Fake_DDL/testing.rb:22:in`join’  
from C:/Documents and  
Settings/PROXIMETRY/Desktop/Autotests/Fake\_DDL/testing.rb:22

#####################################################################  
REPLACING stationStatsTr.stop() by stationStatsTr.kill works as expected  
(stationStats is killed and rulesTr is running). But stop() method  
cannot stop stationStatsTr. Moreover rulesTr doesn’t run (as you can see  
in output) and error occured at the end of script (after set 10 secs in  
join).  
What is going on with this. The idea of the part of code is that only  
one of the threads should run simultaneously. The rulesTr should be able  
to stop and start staionStatsTr.

Any help will be helpful.  
Thanks in advance,  
MT
