- 论坛徽章:
- 0
|
回复 #44 MMMIX 的帖子
我在你那个上面加了一个sleep 2,每起个新的进程要等2秒,
- #!/usr/bin/perl
- use strict;
- use warnings;
- use threads;
- use threads::shared;
- my $thread_num :shared = 0;
- sub start_thread {
- print "Thread ", threads->tid(), " started, current thread numbers $_[0]\n";
- {
- lock($thread_num);
- $thread_num--;
- sleep 2;
- cond_signal($thread_num);
- }
- }
- for (1 .. 200) {
- {
- lock($thread_num);
- cond_wait($thread_num) until $thread_num < 10;
- my $t = threads->create(\&start_thread, $thread_num + 1);
- $t->detach();
-
- $thread_num++;
- }
- }
复制代码
[ 本帖最后由 Perl_Er 于 2009-7-1 21:49 编辑 ] |
|