Home > Archive > ithreads > June 2007 > Question about threads and return codes
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 |
Question about threads and return codes
|
|
| Ransom Briggs 2006-12-14, 4:26 am |
| 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
| |
| Jerry D. Hedden 2006-12-14, 4:26 am |
| Ransom Briggs asked:
> 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.
$? is not shared between threads. What you want to do will work fine.
________________________________________
________________________________________
____
Any questions? Get answers on any topic at www.Answers.yahoo.com. Try it now.
| |
|
|
|
|
|
|
|
|
|
|
|
|
|