- 論壇徽章:
- 0
|
本帖最后由 yeahnoob 于 2014-09-24 23:35 編輯
LZ一開始關(guān)于lock和cond_wait 的內(nèi)容應(yīng)該是不正確的。
lock只是一個聲明性質(zhì)的函數(shù),聲明出一個阻塞式變量,單獨(dú)不會直接影響sub的執(zhí)行。
cond_wait的實(shí)際用途,恰好是LZ一開始對lock函數(shù)理解的用途。另外兩個cond_signal和cond_broadcast在perldoc里面我覺得說的是很清楚,
- cond_signal VARIABLE
- The "cond_signal" function takes a locked variable as a parameter and unblocks one thread that's "cond_wait"ing on that variable. If
- more than one thread is blocked in a "cond_wait" on that variable, only one (and which one is indeterminate) will be unblocked.
- If there are no threads blocked in a "cond_wait" on the variable, the signal is discarded. By always locking before signaling, you can
- (with care), avoid signaling before another thread has entered cond_wait().
- "cond_signal" will normally generate a warning if you attempt to use it on an unlocked variable. On the rare occasions where doing this
- may be sensible, you can suppress the warning with:
- { no warnings 'threads'; cond_signal($foo); }
- cond_broadcast VARIABLE
- The "cond_broadcast" function works similarly to "cond_signal". "cond_broadcast", though, will unblock all the threads that are blocked
- in a "cond_wait" on the locked variable, rather than only one.
復(fù)制代碼 |
|