[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

problem on enpanding array?

Matthias Ludwig

8/11/2006 8:32:00 AM

Hi,

i wrote a little class for thread-pools, but there is a problem
expanding args on a method-call.

def new_thread(*args, &action)
# wait until a slot in the pool is free
...

# start thread
threads << Thread.new { action.call(*args) }
end

In the block (which is the "work to do in the thread") the args
should be available with |arg1, arg2, ...|, but the aren't. They
are still in one array (args).

Any ideas what's going wrong?

best regards,
Matthias
1 Answer

Ken Bloom

8/11/2006 2:54:00 PM

0

On Fri, 11 Aug 2006 17:32:27 +0900, Matthias Ludwig wrote:

> Hi,
>
> i wrote a little class for thread-pools, but there is a problem
> expanding args on a method-call.
>
> def new_thread(*args, &action)
> # wait until a slot in the pool is free
> ...
>
> # start thread
> threads << Thread.new { action.call(*args) }
> end
>
> In the block (which is the "work to do in the thread") the args
> should be available with |arg1, arg2, ...|, but the aren't. They
> are still in one array (args).
>
> Any ideas what's going wrong?
>
> best regards,
> Matthias
> Attachment not shown: MIME type application/pgp-signature

Works for me:

$threads=[]
def new_thread(*args, &action)
# start thread
$threads << Thread.new { action.call(*args) }
end

new_thread(7,"Hello") {|n,m| n.times{sleep 1; puts m}}

sleep 10


--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...