develooper Front page | perl.ithreads | Postings from January 2010

Re: Threading within another thread

Thread Previous | Thread Next
From:
Francesco Nidito
Date:
January 29, 2010 03:05
Subject:
Re: Threading within another thread
Message ID:
e159ecb61001290305i4478a617ncffc79f5d1385428@mail.gmail.com
It is possible to spawn a thread from inside another thread but
remember that the thread will belong to the process and not to the
thread that spawned it (as usually with threads...).

use threads;

sub InternalThread {
     # do something...
}

sub ExternalThread {
    # do something...
    my $it = threads->create(\&InternalThread);
    # do something else in parallel with InternalThread...
    $it->join();
    # do the rest
}

# main()
my $et = threads->create(\&ExternalThread);
$et->join();

On Thu, Jan 28, 2010 at 6:42 PM, Danny Wong (dannwong)
<dannwong@cisco.com> wrote:
> Hi Perl Thread GURUS,
>        Is it possible to run threads within another thread? Is so, any
> example on how to do it? Thanks.
>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About