In the above, the threads object is returned to the parent thread in scalar context, and the thread's entry point function foo will be called in list context such that the parent thread can receive a list from the ->join() call. Similarly, if you need the threads object, but your thread will not be returning a value (i.e., void context), you would do the following:my $thr = threads->create({'context' => 'list'}, \&foo); ... my @results = $thr->join();
The context type may also be used as the key in the parameter hash followed by a true value:my $thr = threads->create({'context' => 'void'}, \&foo); ... $thr->join();
threads->create({'scalar' => 1}, \&foo); ... my ($thr) = threads->list(); my $result = $thr->join();
# Create thread in list context my ($thr) = threads->create(...); # Create thread in scalar context my $thr = threads->create(...); # Create thread in void context threads->create(...);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Explicit thread context
by BrowserUk (Patriarch) on May 23, 2006 at 16:25 UTC | |
by jdhedden (Deacon) on May 23, 2006 at 17:24 UTC | |
Re: Explicit thread context
by diotalevi (Canon) on May 23, 2006 at 15:40 UTC | |
by jdhedden (Deacon) on May 23, 2006 at 16:46 UTC | |
by gellyfish (Monsignor) on May 23, 2006 at 15:50 UTC | |
|