亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2790 | 回復(fù): 5
打印 上一主題 下一主題

跪求大神解答 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2014-09-23 17:00 |只看該作者 |倒序瀏覽
我目前在學(xué)習(xí)一個Perl模塊,叫threads::shared

在這個模塊里我對于cond_broadcast這個函數(shù)不是很理解。其實(shí)說實(shí)話,我對于多線程就不是很理解。
比如lock函數(shù)的作用是什么,為什么要有l(wèi)ock函數(shù)
同樣的cond_wait函數(shù)又有什么作用?
cond_signal和cond_broadcast函數(shù)呢?

我看了perl的幫助文檔,對于這些函數(shù)有一些理解,但是還是需要大神給予確定才行。


首先是lock函數(shù)
比如有如下代碼:
```
sub fun1{
    lock $public_var;
    ....
}
```
這樣一來,在多線程運(yùn)行時,當(dāng)運(yùn)行到lock這里時,其他函數(shù)不能對$public_var進(jìn)行修改,直到fun1函數(shù)運(yùn)行完成。


其次是cond_wait函數(shù)
比如有如下代碼:
```
sub fun2{
   cond_wait $public_var;
   ....
}
```
這樣一來,如果同一時間運(yùn)行fun1和fun2兩個函數(shù),那么首先會在fun1中可以修改$public_var,運(yùn)行完fun1后,在fun2中可以修改$public_var。

是這樣嗎?我對這個函數(shù)理解不清晰......


最后是cond_signal和cond_broadcast
這兩個函數(shù)就完全沒有理解了.......


所以跪求大神給予指導(dǎo){:3_200:}

論壇徽章:
0
2 [報告]
發(fā)表于 2014-09-23 17:04 |只看該作者
消滅0回復(fù)!

論壇徽章:
0
3 [報告]
發(fā)表于 2014-09-24 07:51 |只看該作者
頂頂頂頂頂頂頂頂頂

論壇徽章:
0
4 [報告]
發(fā)表于 2014-09-24 17:27 |只看該作者
頂頂頂頂頂頂頂頂頂

論壇徽章:
0
5 [報告]
發(fā)表于 2014-09-24 23:28 |只看該作者
本帖最后由 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ù)理解的用途。
  1. perldoc threads::shared
復(fù)制代碼
另外兩個cond_signal和cond_broadcast在perldoc里面我覺得說的是很清楚,

  1.        cond_signal VARIABLE
  2.            The "cond_signal" function takes a locked variable as a parameter and unblocks one thread that's "cond_wait"ing on that variable. If
  3.            more than one thread is blocked in a "cond_wait" on that variable, only one (and which one is indeterminate) will be unblocked.

  4.            If there are no threads blocked in a "cond_wait" on the variable, the signal is discarded. By always locking before signaling, you can
  5.            (with care), avoid signaling before another thread has entered cond_wait().

  6.            "cond_signal" will normally generate a warning if you attempt to use it on an unlocked variable. On the rare occasions where doing this
  7.            may be sensible, you can suppress the warning with:

  8.              { no warnings 'threads'; cond_signal($foo); }

  9.        cond_broadcast VARIABLE
  10.            The "cond_broadcast" function works similarly to "cond_signal".  "cond_broadcast", though, will unblock all the threads that are blocked
  11.            in a "cond_wait" on the locked variable, rather than only one.
復(fù)制代碼

論壇徽章:
0
6 [報告]
發(fā)表于 2014-09-25 08:57 |只看該作者
謝謝你~~一語點(diǎn)醒夢中人回復(fù) 5# yeahnoob


   
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP