Hello,
I'm working on a threaded perl program whose function is basically made
up of one master thread and multiple worker threads which are fed
commands to run. The problem that I'm having conceptually is if I can
safely use the variable $?, is this defined per thread or per process?
ie: if I have multiple commands running at the same time would it be
possible for the following interaction to happen? thread1 runs a
command which writes 0 to $?, thread2 runs a command which writes 1 to
$?, then thread1 and thread2 both read $? and see a 1.
Here's what I would like to do, will it have this problem, and if so,
how can I avoid this?
sub thread_func {
my ($threadid) = @_;
my $queue_input;
print "Thread $threadid has started\n";
while (defined($queue_input =
$input_queues{$threadid}->dequeue())) {
print "Popped off $queue_input\n";
my ($data_id, $src_filename, $dst_filename) =
split(/\|/, $queue_input);
# do my important work here
my $copyoutput = `cp $src_filename $dst_filename`;
my $returncode = $?; # here's what I am wondering about
$output_queue->enqueue($queue_input+1);
}
}
Thank you,
Ransom