At 05:42 PM 4/19/2006 +0200, Daniel McBrearty wrote:
>If I have a thread that is sleeping indefinitely, how can I wake it from
>some other thread?
First of all u should be use'ing threads, not Thread. Thread is obsolete.
To get another thread to wake up u first have to put it to sleep somehow.
Then u wake it by sending it a message of some kind. There are several ways
to do that. U can use a shared variable, a semaphore, or a message queue.
The advantage of the semaphore is that it can perform the function of
putting it to sleep and waking it. Read the perlthrtut in the Active State
user guide.
use threads;
use Thread::Semaphore;
$semaphore = new Thread::Semaphore(0); # is zero
$t1 = threads->create("sub1");
print "waiting 5...\n" and sleep 5;
# now that $semaphore is 1, the down can unblock
$semaphore->up;
sub sub1 {
# thread blocks until $semaphore can be non negative
$semaphore->down;
print "doing something";
$semaphore->up;
}
--
REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=--
"...ne cede malis"
00000100
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs