Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Threading Question

Reply
Thread Tools

Threading Question

 
 
Sylvain Joyeux
Guest
Posts: n/a
 
      11-16-2006
[previous code snipped]
> timer = Timer.new( 1,5){puts "x"}
> timer.start

<= the application finishes here

You have to call #join on your thread or the application finishes and the
thread is killed

Sylvain

 
Reply With Quote
 
 
 
 
Mike Houghton
Guest
Posts: n/a
 
      11-16-2006
Sylvain Joyeux wrote:
> [previous code snipped]
>> timer = Timer.new( 1,5){puts "x"}
>> timer.start

> <= the application finishes here
>
> You have to call #join on your thread or the application finishes and
> the
> thread is killed
>
> Sylvain


Yes! Thanks, the light just went on...

class Timer

def initialize( period, count, &action )

@period = period
@count = count
@action = action

end #initialize

def start

@thr = Thread.new do
@count.times do
@action.call
sleep(@period)
end #do
end #do


end #start

def join
@thr.join
end


end #class Timer

timer = Timer.new( 1,5){puts "x"}
timer.start
timer.join

Ideally what I'd now like to do is make the Timer class such that I
don't need to have a public join method and the @thr.join is, somehow,
called intrinsically.


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: threading in PyQt vs threading in standard library Steven Woody Python 0 01-09-2009 07:48 AM
threading in PyQt vs threading in standard library Steven Woody Python 0 01-09-2009 07:15 AM
Cooperative threading preemptive threading - a bit confused failure_to@yahoo.co.uk Java 9 12-29-2007 01:10 AM
Threading question Frederick Wilson Firefox 1 12-22-2004 12:23 AM
disconnected DataSet multi-threading question Alina ASP .Net 0 07-16-2003 04:23 PM



Advertisments