- 论坛徽章:
- 0
|
自己写了一个线程池,出现一点问题
程序在附件中,以下是程序的输出
ID: -1210315856 thread join in war!
ID: -1218708560 thread join in war!
ID: -1227101264 thread join in war!
ID: -1235493968 thread join in war!
ID: -1243886672 thread join in war!
1 idle :5, counter:5
2 idle :4, counter:5
3 idle :3, counter:5
4 idle :3, counter:5
5 idle :3, counter:5
6 idle :3, counter:5
7 idle :3, counter:5
8 idle :3, counter:5
9 idle :3, counter:5
10 idle :3, counter:5
11 idle :3, counter:5
12 idle :3, counter:5
13 idle :3, counter:5
14 idle :3, counter:5
15 idle :3, counter:5
16 idle :3, counter:5
17 idle :3, counter:5
18 idle :3, counter:5
19 idle :3, counter:5
20 idle :3, counter:5
1 :one thread done
2 :one thread done
5 :one thread done
3 :one thread done
4 :one thread done
21 idle :0, counter:5
ID: -1252279376 thread join in war!I am forced
22 idle :0, counter:6
ID: -1260672080 thread join in war!I am forced
6 :one thread done
7 :one thread done
8 :one thread done
9 :one thread done
10 :one thread done
11 :one thread done
12 :one thread done
23 idle :0, counter:7
ID: -1269064784 thread join in war!I am forced
i am waiting them
13 :one thread done
14 :one thread done
15 :one thread done
16 :one thread done
17 :one thread done
i quit because shutdown
i quit because shutdown
18 :one thread done
i quit because shutdown
19 :one thread done
i quit because shutdown
20 :one thread done
i quit because shutdown
21 :one thread done
i quit because shutdown
22 :one thread done
i quit because shutdown
23 :one thread done
i quit because shutdown
should i destroy mutex now ?
mutex destroy OK
In destroy, idle:0,counter:0
destroy done
工作线程睡眠4秒,add_work添加请求的速度很快,idle应该早就为0了
可是不知为什么,idle没有被及时更新,add_work误以为还有空闲线程
其实请求数量早已超过线程数量,add_work应该创建新的线程
可是由于idle没被更新而没有创建更多线程,导致请求等待
怎样解决这个问题?
[ 本帖最后由 duyaolin 于 2007-11-17 13:59 编辑 ] |
|