problem on enpanding array?

M

Matthias Ludwig

--y0ulUmNC+osPPQO6
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

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

--y0ulUmNC+osPPQO6
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (OpenBSD)

iD8DBQFE3FFZbaBeCFlfXPMRAim/AJ41OnjKKhxlm8iiQMh8SLMGbR+VxwCgklYU
9G1v1L1vot2ev9/39X2qNps=
=ndGy
-----END PGP SIGNATURE-----

--y0ulUmNC+osPPQO6--
 
K

Ken Bloom

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,687
Latest member
IngridXxj

Latest Threads

Top