Topic: 哪位可以给说明一下join()这东西...

  Print this page

1.哪位可以给说明一下join()这东西... Copy to clipboard
Posted by: merlin8866
Posted on: 2004-11-11 21:48

看过API和别的一些书,但还是很模糊...
到底应该怎样用?
什么时候用?
跟wait()有什么不同?

2.Re:哪位可以给我说明一下join()这东西... [Re: merlin8866] Copy to clipboard
Posted by: caleb
Posted on: 2004-11-11 21:51

join() wait for completion of another thread,

wait() will make current thread release the lock it holds,
and wait for notify()/notifyall().

3.Re:哪位可以给我说明一下join()这东西... [Re: merlin8866] Copy to clipboard
Posted by: merlin8866
Posted on: 2004-11-11 22:28

什么意思?
那wait()也是等待completion of another thread啊,不是吗?
是join()不需要noitfy(),自己激活自己吗?
还是说join()不会解锁?

请说清楚些好吗...我真的非常的不明白啊~~~

4.Re:哪位可以给我说明一下join()这东西... [Re: merlin8866] Copy to clipboard
Posted by: merlin8866
Posted on: 2004-11-11 23:49

刚才又看了一下
join(long a)是不是就是当线程被interrupted a毫秒后关闭(变成死线程)?
如果是,那跳回哪个线程呢?

5.Re:哪位可以给我说明一下join()这东西... [Re: merlin8866] Copy to clipboard
Posted by: caleb
Posted on: 2004-11-13 00:36

If my memory serve me well .. Tongue ..

in thread t1, it calls t2.join(), t1 will move from "running state"
to "blocked for t2 complete state". it will be promoted to "ready to run"
state, if 1> t2 compelete, 2> t1 being interupted, 3> t1 time out.

in thread t1, and t1 hold the lock of object o1, it call wait(), t2 will
release o1 lock, and move from "runing state" to "waiting for notification"
it will be promoted to "lock accuisition state" if 1> notify/notifyall called in
another thread t2, 2> t1 time out, 3> t1 being interupted.
if t1 finaly accqure the lock again, it will move to "ready to run" state.

hopely this helps .. Smile ..


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923