Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Perl
Perl Misc
Checking thread status
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="programmacist, post: 4795032"] Hello, I'm trying to accomplish something that seems, IMHO, like it should be relatively straightforward, but I can't seem to figure it out. I create a worker thread that goes off and processes for an extended period of time. Meanwhile, I would like to continue processing in the main thread, and periodically check whether the worker thread is finished. The example below illustrates this: use threads; sub work { print "Worker has started\n"; sleep (3); die "Worker is finished\n"; } my $worker = threads->create('work'); while (** worker is not done **) { print "Main is performing a task\n"; sleep (1); } $worker->join(); print "Moving on...\n"; What I can't seem to figure out is how to accomplish the ** worker is not done ** part. I have tried using threads->list to see the number of running threads, but this continues to show the worker, even after it has supposedly ended. I have also tried the deprecated Thread module, so I could look at $worker->done. However, it too, continues to say that the worker is not done. I thought about using a shared variable as a flag, but this doesn't allow for the case of an abnormally terminated worker thread. One clue I may have is that the output includes the following: thread failed to start: Worker is finished when the worker thread dies. I'm wondering why it thinks that the thread didn't start? I am using ActiveState perl 5.8.6 on a WindowsXP machine, though I've also tried it on Windows 2000. Any help provided would be greatly appreciated! Cheers, Ralph [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Perl
Perl Misc
Checking thread status
Top