帮忙看看这个多线程的例子错在哪儿?(win32下)

帮忙看看这个多线程的例子错在哪儿?(win32下)

帮忙看看这个多线程的例子错在哪儿?(win32下)

use strict;
use warnings;
use threads;
use threads::shared;

my $wait_var = 0;
share($wait_var);

sub fun1(){
print "enter fun1.\n";
lock $wait_var;
print "before fun1 set value.\n";
$wait_var = 1;
print "after fun1 set value.\n";
cond_signal($wait_var);
cond_wait $wait_var until $wait_var == 2;

print "before fun1 set value.\n";
$wait_var = 1;
cond_signal($wait_var);
print "after fun1 set value.\n";
cond_wait $wait_var until $wait_var == 2;
print "before fun1 set value.\n";
$wait_var = 1;
print "after fun1 set value.\n";
cond_signal($wait_var);
print "fun1 end\n";
}

sub fun2(){
print "enter fun2.\n";
lock $wait_var;
cond_wait $wait_var until $wait_var == 1;
print "before fun2 set value.\n";
$wait_var = 2;
print "after fun2 set value.\n";
cond_signal($wait_var);
print "fun2 before con_wait.\n";
cond_wait $wait_var until $wait_var == 1;
print "before fun2 set value.\n";
$wait_var = 2;
print "after fun2 set value.\n";
cond_signal($wait_var);
# cond_wait $wait_var until $wait_var == 1;
print "fun2 end\n";
}

threads->new(\&fun2);
threads->new(\&fun1);


while (1){
sleep(2);
}




   

用了threads->new以后, 要用threads-join来结束相关的线程。你这这里这样使用threads是完全错了`[CCB]12[/CCB][CCB]12[/CCB]