mecrazycoder has asked for the wisdom of the Perl Monks concerning the following question:

Is there any way for waking a sleeping thread using its thread ID in Perl ? Thanks in advance

Replies are listed 'Best First'.
Re: How to wake a thread in Perl
by Anonymous Monk on May 14, 2011 at 12:14 UTC
    How did you put it to sleep, using sleep? I don't think you can stop sleep early , except maybe using signals ...
Re: How to wake a thread in Perl
by Khen1950fx (Canon) on May 14, 2011 at 19:06 UTC
    You could use Thread::Suspend to put your thread to bed. With Thread::Suspend, you can suspend and resume a thread. For example, just using one thread:
    #!/usr/bin/perl use strict; use warnings; use threads ('stack_size' => 16384); use Thread::Suspend; $|=1; sub start_thread { my @args = @_; print('Thread started ', join(' ', @args,), "\n"); } my $thr = threads->create(\&start_thread); $thr->join(); my $tid = threads->self; $thr->suspend($tid); sleep 1; $thr->resume($tid);