For Programmers: Free Programming Magazines  


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.
Asdfdsfsdfadsfasdf

2007-03-19, 4:29 am

Jessica Alba In Anal Action Movie!
http://Jessica-Alba-In-Anal-Action-...hp?movie=148803
Enceted99

2007-04-30, 5:28 am

Mel Gibson Spanking!
http://Mel-Gibson-spanking.info/Win...hp?movie=148803
Take

2007-06-21, 9:52 pm

Alyssa Milano Undressing & Shows Tiny Dick Posing!
http://www.videomoviesonline.com/PlayMovie?q=726071

Olsen Twins stripping in the kitchem!
http://www.videomoviesonline.com/WatchTube?movie=726071

Jennifer Aniston takes cock from behind!
http://www.videomoviesonline.com/a?q=726071

Jennifer Lopez Undressing & Shows Tiny Dick Posing!
http://www.videomoviesonline.com/Wi....asp?vid=726071

Carmen Electra Spreading Her Tight Ass!
http://www.videomoviesonline.com/WatchTube?q=726071
Adanpohated8

2007-06-24, 12:19 pm

http://www.videomoviesonline.com/player.wmv?q=726071
Snaggle

2007-06-30, 1:39 pm

Lindsay Lohan and Tara Reid Spoiling Lucky Girl!
http://www.yourtubeaudio.com/Play?q=1673286
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com