Sharing between threads
Hey all. I'm working with a Perl script where I want to break off a
certain part of execution into multiple threads. Right now, I'm
attempting to do a calculation based on two variables, and based on a
certain condition, put them back into a shared array.
Unfortunately, I'm running into a problem. I want the array to be
shared, but I don't want the two variables that the computation is done
on to be shared, since different threads are going to be working
simultaneously on different values of the variables.
I also don't want to join() back threads, so just returning the values
won't work. This is due to the fact that there will be a flag to the
program limiting the number of spawned threads. With my current
implementation, I just make a semaphore with the maximum number of
threads as its argument, and then do a down() before executing each
thread, and an up() when finishing. So no, a join() won't work in this
case, because it would eliminate my ability to accurately and
efficiently limit the number of executing threads at any given time.
Is this at all possible?
Stephen Touset <firstname.lastname@example.org>