# Thread closing?

**URL:** <https://www.ruby-forum.com/t/thread-closing/146688>\
**Category:** Ruby\
**Created:** [August 24, 2008, 4:49am UTC](https://www.ruby-forum.com/t/thread-closing/146688 "2008-08-24T04:49:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [August 24, 2008, 4:49am UTC](https://www.ruby-forum.com/t/thread-closing/146688/1 "2008-08-24T04:49:27Z")

</div>

@t1 = Thread.new do  
b = false  
until b == true  
sleep 10  
puts “you are getting cold!”  
end  
end

So, that gets called when a play enters a ‘cold’ room. I want to set in  
the ‘leave’ event:

@t1.close

or something to that effect, but i get errors when trying to call  
@t1.exit… Any thoughts?

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [August 25, 2008, 3:17pm UTC](https://www.ruby-forum.com/t/thread-closing/146688/2 "2008-08-25T15:17:32Z")

</div>

Tim M. wrote:

> @t1 = Thread.new do  
> b = false  
> until b == true  
> sleep 10  
> puts “you are getting cold!”  
> end  
> end
> 
> So, that gets called when a play enters a ‘cold’ room. I want to set in  
> the ‘leave’ event:
> 
> @t1.close
> 
> or something to that effect, but i get errors when trying to call  
> @t1.exit… Any thoughts?

You can call @t1.raise or @t1.kill, however those methods are pretty  
scary. I’d do something like polling:  
b = false  
@t1 = Thread.new { sleep 10 until b == true}  
and set b to true elsewhere in the code.  
-=R
