設(shè)計

Why build concurrency on the ideas of CSP?

為什么要基于 CSP 的思想來構(gòu)建并發(fā)火俄?

Concurrency and multi-threaded programming have over time developed a reputation for difficulty. We believe this is due partly to complex designs such as pthreads and partly to overemphasis on low-level details such as mutexes, condition variables, and memory barriers. Higher-level interfaces enable much simpler code, even if there are still mutexes and such under the covers.
隨著時間的推移,并發(fā)和多線程編程已經(jīng)被認為是困難的适瓦。我們認為,一部分是由于復雜的設(shè)計(例如 pthreads) 犹菇,另一部分是由于過分強調(diào)低級細節(jié)(例如互斥體、條件變量和內(nèi)存屏障)芽卿。更高級別的接口可以使代碼更簡單胳搞,即使在幕后仍然存在互斥體等。

overemphasis
n. 過分的強調(diào);

One of the most successful models for providing high-level linguistic support for concurrency comes from Hoare's Communicating Sequential Processes, or CSP. Occam and Erlang are two well known languages that stem from CSP. Go's concurrency primitives derive from a different part of the family tree whose main contribution is the powerful notion of channels as first class objects. Experience with several earlier languages has shown that the CSP model fits well into a procedural language framework.
為并發(fā)提供高級語言支持的最成功的模型之一來自 Hoare 的通信順序進程 (CSP)肌毅。Occam 和 Erlang 是源自 CSP 的兩種著名語言。Go 的并發(fā)原語源自家族樹的不同部分悬而,其主要貢獻是將通道的概念作為一等對象。幾種早期語言的經(jīng)驗表明笨奠,CSP 模型非常適合過程語言框架。

stem
n. 莖;高腳杯的腳;煙斗柄;詞干;
v. 阻止;

Why goroutines instead of threads?

為什么使用 goroutine 而不是線程般婆?

Goroutines are part of making concurrency easy to use. The idea, which has been around for a while, is to multiplex independently executing functions—coroutines—onto a set of threads. When a coroutine blocks, such as by calling a blocking system call, the run-time automatically moves other coroutines on the same operating system thread to a different, runnable thread so they won't be blocked. The programmer sees none of this, which is the point. The result, which we call goroutines, can be very cheap: they have little overhead beyond the memory for the stack, which is just a few kilobytes.
Goroutine 是讓并發(fā)變得易于使用的一部分。這個想法已經(jīng)存在了一段時間蔚袍,即將獨立執(zhí)行的函數(shù)(協(xié)程)復用到一組線程上。當協(xié)程阻塞時,例如通過調(diào)用阻塞系統(tǒng)調(diào)用晋辆,運行時會自動將同一操作系統(tǒng)線程上的其他協(xié)程移動到不同的可運行線程渠脉,這樣它們就不會被阻塞瓶佳。程序員看不到這些,這就是重點涩哟。我們稱之為 goroutine 的結(jié)果可能非常便宜:除了堆棧內(nèi)存(只有幾千字節(jié))之外,它們幾乎沒有任何開銷贴彼。

multiplex
n. 多廳影院潜腻,多劇場影劇院;多路,復用;

To make the stacks small, Go's run-time uses resizable, bounded stacks. A newly minted goroutine is given a few kilobytes, which is almost always enough. When it isn't, the run-time grows (and shrinks) the memory for storing the stack automatically, allowing many goroutines to live in a modest amount of memory. The CPU overhead averages about three cheap instructions per function call. It is practical to create hundreds of thousands of goroutines in the same address space. If goroutines were just threads, system resources would run out at a much smaller number.
為了使堆棧變小融涣,Go 的運行時使用可調(diào)整大小的有界堆棧。新創(chuàng)建的 Goroutine 被賦予幾千字節(jié)威鹿,這幾乎總是足夠的。如果不是忽你,運行時會自動增加(和縮小)用于存儲堆棧的內(nèi)存科雳,從而允許許多 goroutine 駐留在適量的內(nèi)存中。每個函數(shù)調(diào)用的 CPU 開銷平均約為 3 個廉價指令脓杉。在同一地址空間中創(chuàng)建數(shù)十萬個 goroutine 是很實用的。如果 goroutine 只是線程球散,那么系統(tǒng)資源就會以更少的數(shù)量耗盡。

minted
adj. 嶄新的蕉堰;新制作的;剛完成的;

instructions
n. 操作指南;用法說明;指示;命令( instruction的名詞復數(shù) );(計算機的)指令;教導;教誨;
adj. 說明用法的嘁灯,操作指南的;

Why are map operations not defined to be atomic?

為什么map操作沒有定義為原子操作?
After long discussion it was decided that the typical use of maps did not require safe access from multiple goroutines, and in those cases where it did, the map was probably part of some larger data structure or computation that was already synchronized. Therefore requiring that all operations grab a mutex would slow down most programs and add safety to few. This was not an easy decision, however, since it means uncontrolled map access can crash the program.
經(jīng)過長時間的討論丑婿,我們決定map的典型使用不需要從多個 goroutine 進行安全訪問没卸,并且在需要安全訪問的情況下秒旋,map可能是已經(jīng)同步的某些較大數(shù)據(jù)結(jié)構(gòu)或計算的一部分。因此迁筛,要求所有map操作獲取互斥鎖會減慢大多數(shù)程序的速度煤蚌,并增加少數(shù)程序的安全性细卧。然而,這不是一個容易的決定贪庙,因為這意味著不受控制的map訪問可能會使程序崩潰。

The language does not preclude atomic map updates. When required, such as when hosting an untrusted program, the implementation could interlock map access.
該語言并不排除原子map更新止邮。當需要時,例如托管不受信任的程序時导披,該實現(xiàn)可以互鎖map訪問。

preclude
vt. 阻止;排除;妨礙;

interlock
v. 互鎖;連鎖;

Map access is unsafe only when updates are occurring. As long as all goroutines are only reading—looking up elements in the map, including iterating through it using a for range loop—and not changing the map by assigning to elements or doing deletions, it is safe for them to access the map concurrently without synchronization.
僅當發(fā)生更新時map訪問才是不安全的撩匕。只要所有 goroutine 都只是讀取(在map中查找元素滑沧,包括使用for 、range迭代它)滓技, 喝不通過分配元素或執(zhí)行刪除來更改map棚潦,那么它們在不同步的情況下并發(fā)訪問map是安全的令漂。

As an aid to correct map use, some implementations of the language contain a special check that automatically reports at run time when a map is modified unsafely by concurrent execution.
作為正確map使用的輔助手段丸边,該語言的某些實現(xiàn)包含特殊檢查,當并發(fā)執(zhí)行不安全地修改映射時妹窖,該檢查會在運行時自動報告。

Will you accept my language change?

您能接受我的語言更改嗎骄呼?

People often suggest improvements to the language—the mailing list contains a rich history of such discussions—but very few of these changes have been accepted.
人們經(jīng)常建議改進該語言—— 郵件列表 包含此類討論的豐富歷史——但這些更改很少被接受判没。

Although Go is an open source project, the language and libraries are protected by a compatibility promise that prevents changes that break existing programs, at least at the source code level (programs may need to be recompiled occasionally to stay current). If your proposal violates the Go 1 specification we cannot even entertain the idea, regardless of its merit. A future major release of Go may be incompatible with Go 1, but discussions on that topic have only just begun and one thing is certain: there will be very few such incompatibilities introduced in the process. Moreover, the compatibility promise encourages us to provide an automatic path forward for old programs to adapt should that situation arise.
盡管 Go 是一個開源項目,但該語言和庫受到兼容性承諾的保護澄峰,該承諾可以防止破壞現(xiàn)有程序的更改,至少在源代碼級別如此(程序可能需要偶爾重新編譯以保持最新狀態(tài))俏竞。如果您的提案違反了 Go 1 規(guī)范,我們甚至無法接受這個想法魂毁,無論其優(yōu)點如何。Go 未來的主要版本可能與 Go 1 不兼容席楚,但關(guān)于該主題的討論才剛剛開始疚漆,有一點是肯定的:在此過程中引入的此類不兼容性非常少酣胀。此外娶聘,兼容性承諾鼓勵我們?yōu)榕f程序提供一條自動前進路徑,以便在出現(xiàn)這種情況時進行適應(yīng)丸升。

compatibility
n. 并存,相容;兼容性;

Even if your proposal is compatible with the Go 1 spec, it might not be in the spirit of Go's design goals. The article Go at Google: Language Design in the Service of Software Engineering explains Go's origins and the motivation behind its design.
即使您的提案與 Go 1 規(guī)范兼容狡耻,它也可能不符合 Go 的設(shè)計目標精神。《Google 的 Go:軟件工程服務(wù)中的語言設(shè)計》一文 解釋了 Go 的起源及其設(shè)計背后的動機岭皂。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市沼头,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌进倍,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,000評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件陶因,死亡現(xiàn)場離奇詭異,居然都是意外死亡楷扬,警方通過查閱死者的電腦和手機解幽,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,745評論 3 399
  • 文/潘曉璐 我一進店門毅否,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人螟加,你說我怎么就攤上這事±μ剑” “怎么了?”我有些...
    開封第一講書人閱讀 168,561評論 0 360
  • 文/不壞的土叔 我叫張陵黍图,是天一觀的道長。 經(jīng)常有香客問我助被,道長,這世上最難降的妖魔是什么揩环? 我笑而不...
    開封第一講書人閱讀 59,782評論 1 298
  • 正文 為了忘掉前任,我火速辦了婚禮顾犹,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘褒墨。我一直安慰自己,他們只是感情好郁妈,可當我...
    茶點故事閱讀 68,798評論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著噩咪,像睡著了一般。 火紅的嫁衣襯著肌膚如雪剧腻。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,394評論 1 310
  • 那天书在,我揣著相機與錄音拆又,去河邊找鬼栏账。 笑死,一個胖子當著我的面吹牛挡爵,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播甚垦,決...
    沈念sama閱讀 40,952評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼艰亮!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起迄埃,我...
    開封第一講書人閱讀 39,852評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎侄非,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體逞怨,經(jīng)...
    沈念sama閱讀 46,409評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,483評論 3 341
  • 正文 我和宋清朗相戀三年骇钦,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片眯搭。...
    茶點故事閱讀 40,615評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖鳞仙,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情棍好,我是刑警寧澤,帶...
    沈念sama閱讀 36,303評論 5 350
  • 正文 年R本政府宣布借笙,位于F島的核電站,受9級特大地震影響业稼,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜低散,卻給世界環(huán)境...
    茶點故事閱讀 41,979評論 3 334
  • 文/蒙蒙 一骡楼、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧鸟整,春花似錦、人聲如沸朦蕴。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,470評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至降瞳,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間蚓胸,已是汗流浹背挣饥。 一陣腳步聲響...
    開封第一講書人閱讀 33,571評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留沛膳,地道東北人扔枫。 一個月前我還...
    沈念sama閱讀 49,041評論 3 377
  • 正文 我出身青樓,卻偏偏與公主長得像锹安,于是被迫代替她去往敵國和親短荐。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,630評論 2 359

推薦閱讀更多精彩內(nèi)容