in reply to Fun with threads
Here is one normal way to use join:use threads; $| ++; threads->create(\&a); while (1) {} sub a { eval(threads->self->join);#Waiting for Godot print "before return\n";#will not show up }
use threads; $| ++; $child = threads->create(\&a); $child->join; # I am wating the $child thread to finish first print "Main thread stop\n"; sub a { for (1..5) { print "child is still counting, $_\n"; sleep(3); } print "child thread stop\n"; }
This hangs:$| ++; if (($chld = fork()) == 0) { sleep(3); print "child exit\n"; } else { waitpid $chld, 0; print "parent exit\n"; }
$| ++; waitpid $$, 0; #wait for Godot print "exit\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Fun with threads
by znu (Acolyte) on Dec 20, 2002 at 02:39 UTC | |
|
Re: Re: Fun with threads
by submersible_toaster (Chaplain) on Dec 20, 2002 at 06:44 UTC |