Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to implement signal.wait(timeout) ?

Reply
Thread Tools

How to implement signal.wait(timeout) ?

 
 
Jacob
Guest
Posts: n/a
 
      09-30-2008
Hi all

I am writing a ruby server. Something like:

class MyServer

def initialize
@stop_signal = MySignal.new
end

def start
@stop_signal.reset
@thread = Thread.start { run }
end

def stop
@stop_signal.set
@thread.wait
end

def run

while true
do_process if there_is_some_thing_to_process
@stop_signal.wait 5
end

end

end

Is there any class in ruby that has similar functions to MySignal?
It's easy solution in java or .net.

I have googled, and I found a method call 'timeout', but after read
the source code, I found it uses a new thread to handle timeout. I
think It's not good solution, because on my real system (ported
from .net source code), there are some thread running parallel, and
there are using alot of signal.

Thanks
Jacob
 
Reply With Quote
 
 
 
 
Mikel Lindsaar
Guest
Posts: n/a
 
      09-30-2008
On Tue, Sep 30, 2008 at 7:59 PM, Jacob <(E-Mail Removed)> wrote:
> I have googled, and I found a method call 'timeout', but after read
> the source code, I found it uses a new thread to handle timeout. I
> think It's not good solution, because on my real system (ported
> from .net source code), there are some thread running parallel, and
> there are using alot of signal.


You will have to code carefully because ruby uses green threads, not
native threads so you can get blocked on system calls.

I had the same sort of problem, in the end, we solved it with the
terminator gem (1)

See the system timer (2) write up for a good explanation of what is happening.

1) http://www.lindsaar.net/2008/9/11/te...-without-mercy
2) http://ph7spot.com/articles/system_timer

Mikel

--
http://lindsaar.net/
Rails, RSpec and Life blog....

 
Reply With Quote
 
 
 
 
Ron Fox
Guest
Posts: n/a
 
      10-01-2008
Also see the ALARM signal which allows a signal to be delivered after
some time has elapsed.


Mikel Lindsaar wrote:
> On Tue, Sep 30, 2008 at 7:59 PM, Jacob <(E-Mail Removed)> wrote:
>> I have googled, and I found a method call 'timeout', but after read
>> the source code, I found it uses a new thread to handle timeout. I
>> think It's not good solution, because on my real system (ported
>> from .net source code), there are some thread running parallel, and
>> there are using alot of signal.

>
> You will have to code carefully because ruby uses green threads, not
> native threads so you can get blocked on system calls.
>
> I had the same sort of problem, in the end, we solved it with the
> terminator gem (1)
>
> See the system timer (2) write up for a good explanation of what is happening.
>
> 1) http://www.lindsaar.net/2008/9/11/te...-without-mercy
> 2) http://ph7spot.com/articles/system_timer
>
> Mikel
>



--
Ron Fox
NSCL
Michigan State University
East Lansing, MI 48824-1321
 
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: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Column: Implement WPA2-Personal wireless security =?Utf-8?B?a2g=?= Wireless Networking 37 05-18-2006 09:04 PM
How to implement PEAP-EAP-TLD authentication? Edward W. Ray Wireless Networking 4 05-26-2005 10:14 PM
can we implement LIFO using SRL16 ??? Oleg VHDL 5 02-18-2004 10:29 PM
how to implement gated clock and gated partial circuit in VHDL? walala VHDL 3 09-23-2003 10:02 PM



Advertisments