前序依賴和攜帶依賴是怎樣一種關係?

時間 2021-06-26 15:11:00

1樓:窗含嶺

sequnced-before:單執行緒中的的順序語句

sychronizes-with:乙個執行緒中用釋放語義儲存store(memory_order_release),另乙個執行緒中用獲取語義載入load(memory_order_acquire)

dependency-ordered-before:「前序依賴」,乙個執行緒中用釋放語義儲存,另乙個執行緒中用memory_order_consume語義載入

carries-a-dependency-to:「攜帶依賴」,應用於單個執行緒,如果A操作結果要使用操作B的運算元, A將攜帶依賴於B。

攜帶依賴是一種更嚴格的sequnced-before,cppreference裡對其定義為:

Within the same thread, evaluation A that is sequenced-before evaluation B may also carry a dependency into B (that is, B depends on A), if any of the following is true

(1) The value of A is used as an operand of B, except

a) if B is a call to std::kill_dependency

b) if A is the left operand of the built-in &&or , operators.

(2) A writes to a scalar object M, B reads from M

(3) A carries dependency into another evaluation X, and X carries dependency into B

A sequnced-before B,B dependency-ordered-before C,C carries-a-dependency-to D,則A先行於D

A sequnced-before B,B dependency-ordered-before C,C sequnced-before D(普通的sequnced-before,非攜帶依賴),不能推出A先行於D

換個角度:

store(memory_order_release)阻止這個呼叫之前的讀寫操作被重排到後面

load(memory_order_acquire)保證這個呼叫之後的讀寫操作不會重排到前面來

load(memory_order_consume)只阻止對這個原子量有依賴的操作(即攜帶依賴)重排到前面去,而非像memory_order_acquire一樣全部阻止

長期依賴外賣是一種怎樣的體驗?

竹內軟雞翅兒 大二學生,食堂太擠,每天都是吃外賣。吃了兩年最後經常點的也只有兩三家。而且都是去店裡吃過的。體驗,體驗就是蠻方便的吧。而且對於我來說,吃外賣比食堂便宜。 囂張的叔叔 樓下那位小夥子一看就知道沒點過幾次外賣。很多商家是沒啥大問題的,講真,大家都別被百家號謠言蠱惑了,做外賣的幾百上千萬,然...

有乙個很依賴你的室友是一種怎樣的體驗?

淺棲 我舍友每次網上都買很多東西,拿不了就讓我幫忙。我是可以幫,但是每次都讓我幫拿,我都覺得拿我當苦力了。甚至我覺得她有我這個免費勞動力,買的更加勤了,我好人都當爛了。一不幫她拿就給我擺臭臉 冷暴力。開玩笑說要點報酬,不給就不幫她拿,黑臉一橫,說 原來你是這樣的人。舍友的依賴也不只體現在拿快遞上,甚...

和ENTP戀愛是怎樣一種體驗?

PierceTheBoy 想體驗。認識的entp和她物件在一起,總是在逗物件開心 不得不感慨她好會談,套路好多。我親眼看到她把剛用手撬開的蓋子又蓋回去,讓物件去撬開的美妙場景 你物件沒看到,我看到了啊!還有,那個坐大擺錘嚶嚶嚶的傢伙是誰,我不認識 是誰之前坐的時候興奮得笑呵呵來著 好像女生一般都會裝...