[問題] atomic operation 可以完全取代mutex嗎
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux kernel 4.1 + Raspberry pi 1 + gcc 4.8
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
pthread
問題(Question):
最近從板上學到atomic operation
好奇搜尋了一下atomic operation跟pthread mutex的執行速度比較
https://www.arangodb.com/2015/02/comparing-atomic-mutex-rwlocks/
我用RPi跑的結果,mutex需要的時間比g++ atomic多出3-4倍
我的疑問是,既然atomic operation這麼好用,
那以後可以不用mutex直接用atomic operation嗎?
(我目前是用gcc bulti-in sync operation)
我自己看mutex的原理好像就是嚴格跟複雜一點的atomic operation?
1.以我自己的理解,在單核系統atomic operation應該可以替代mutex?
(同一時間只有一個thread能run的情況下,應該比較容易同步吧?)
還是我考慮的太少?
2.使用pthread_cond_wait和pthread_cond_signal 的情況下
一般都是用mutex來配合,如果我改用atomic operation的test and set來作OK嗎?
3.在多核的情況下,mutex是唯一解嗎?
還是這跟同時間企圖讀寫該critical section 的thread數目有關?
這好像應該是作業系統的問題?
如果有違板規請告知
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 90.41.214.241
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1446454953.A.4B8.html
推
11/02 18:23, , 1F
11/02 18:23, 1F
→
11/02 18:23, , 2F
11/02 18:23, 2F
→
11/02 18:24, , 3F
11/02 18:24, 3F
→
11/02 18:24, , 4F
11/02 18:24, 4F
→
11/02 18:24, , 5F
11/02 18:24, 5F
→
11/02 18:24, , 6F
11/02 18:24, 6F
→
11/02 18:25, , 7F
11/02 18:25, 7F
→
11/02 18:25, , 8F
11/02 18:25, 8F
→
11/02 18:26, , 9F
11/02 18:26, 9F
→
11/02 18:26, , 10F
11/02 18:26, 10F
→
11/02 19:51, , 11F
11/02 19:51, 11F
→
11/02 19:51, , 12F
11/02 19:51, 12F