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";
In reply to Re: Fun with threads
by pg
in thread Fun with threads
by znu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |