For Programmers: Free Programming Magazines  


Home > Archive > Ruby > August 2005 > Re: Rogue threads found! The plot thickens....









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Rogue threads found! The plot thickens....
Eric Hodel

2005-08-31, 9:57 pm

On 31 Aug 2005, at 14:51, Eric Hodel wrote:

> On 30 Aug 2005, at 16:40, Townley, Andrew wrote:
>
>
> If you need safe concurrent access like a Queue and timeouts you
> may find rinda/tuplespace.rb useful. Somewhere around here I have
> a stream implementation for it (but its not terribly difficult to
> write from scratch). I think it can be modified to have timeouts
> on pop.
>
>
> Give me a bit and I think I can make your test program with with a
> TupleSpace streams.


$ cat test.rb
require 'ts_stream'

ts = Rinda::TupleSpace.new 1
stream = Rinda::Stream.new ts, 1

def read(stream, timeout)
puts "READ: #{stream.length} elements"
puts "*** #{stream.pop timeout} ***"
rescue Rinda::Stream::ClosedError
puts "CLOSED: #{stream.length} elements"
rescue Rinda::Stream::TimeoutError
puts "TIMEOUT: #{stream.length} elements"
end

6.times { read stream, 1 }
stream.push "one"
6.times { read stream, 1 }

p Thread.list
$ ruby test.rb
READ: 0 elements
TIMEOUT: 0 elements
READ: 0 elements
TIMEOUT: 0 elements
READ: 0 elements
TIMEOUT: 0 elements
READ: 0 elements
TIMEOUT: 0 elements
READ: 0 elements
TIMEOUT: 0 elements
READ: 0 elements
TIMEOUT: 0 elements
READ: 1 elements
*** one ***
READ: 0 elements
TIMEOUT: 0 elements
READ: 0 elements
TIMEOUT: 0 elements
READ: 0 elements
TIMEOUT: 0 elements
READ: 0 elements
TIMEOUT: 0 elements
READ: 0 elements
TIMEOUT: 0 elements
[#<Thread:0x33898c sleep>, #<Thread:0x1c1740 run>]


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com