in reply to threads->join

I think it is a documentation problem in perlthrtut. The documentation of threads->join states specifically:
$thread->join
This will wait for the corresponding thread to join. When the thread finishes, join() will return the return values of the entry point function. If the thread has been detached, an error will be thrown.

The context (scalar or list) of the thread creation is also the context for join(). This means that if you intend to return an array from a thread, you must use "my ($thread) = threads-"new(...)>, and that if you intend to return a scalar, you must use "my $thread = ...".

Applied to your example, this would mean:

($thr) = threads->new(\&sub1);

Liz

Update:
Apparently the above documentation is in 5.8.1, and not in 5.8.0. I guess you could say it's one more documentation bug that was fixed by 5.8.1. Sorry for the possible confusion.

Replies are listed 'Best First'.
Re: Re: threads->join
by powerman (Friar) on Oct 05, 2003 at 22:53 UTC
    Wow. Thanks. But... I've checked threads module documentation before post here! Here is it:

    $thread = threads->create(function, LIST)
    This will create a new thread with the entry point function and give it LIST as parameters. It will return the corresponding threads object. The new() method is an alias for create().
    $thread->join
    This will wait for the corresponding thread to join. When the thread finishes, join() will return the return values of the entry point function. If the thread has been detached, an error will be thrown. If the program exits without all other threads having been either joined or detached, then a warning will be issued. (A program exits either because one of its threads explicitly calls exit(), or in the case of the main thread, reaches the end of the main program file.)

    I'm using perl 5.8.0 and this is text from `perldoc threads`. So, where you find your version of this documentation?