- 论坛徽章:
- 145
|
回复 3# 522468522
$ time perl test_threads.pl
Running thread 1 sleep 10s......
Running thread 2 sleep 10s......
Thread 1 done!
Thread 2 done!
real 0m10.147s
user 0m0.004s
sys 0m0.088s
$ time perl test_function.pl
Running thread 1 sleep 10s......
Thread 1 done!
Running thread 2 sleep 10s......
Thread 2 done!
real 0m20.124s
user 0m0.004s
sys 0m0.064s
$ diff test_threads.pl test_function.pl
5,9c5,6
< my $t1 = threads->create(\&T1); #调用线程1
< my $t2 = threads->create(\&T2); #调用线程2
<
< $t1->join;
< $t2->join;
---
> &T1();
> &T2();
|
|