作者jasonkey123 (jasonkey123)
看板C_and_CPP
標題[問題] 多執行緒存取資料庫問題
時間Sat Aug 27 19:32:20 2016
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
vc
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
mysql
問題(Question):
當c程式有多個thread,同時對db的 某 table做寫入時,
需要自己加lock嗎?還是資料庫會自己處理,不需自己介入?
如 thread 1 對 test table的 row 1做update
thread 2 對 test table的 row 3做update
thread 3 對 test table的 row 2做update
my_thread()
{
lock(mylock)
{
update_db();
}
}
在my_thread()裡的 lock 需要加嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.100.69.4
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1472297542.A.E26.html
→ pttworld: debugger開了,點進去update_db裡看實作。 08/27 22:27
→ pttworld: 而如果你在update_db下一行下斷點就可以確定是否需加。 08/27 22:28
→ bluesoul: 看文件,該API 是否thread safe 08/28 07:23