Thread Synchronization
Problem
thread 之間是互相信任的,所以他們之間共用了很多資源(像是 heap、file descriptor…),但是這樣當兩個 thread 同時存取同塊記憶體,就可能造成 race condition
像是兩個 thread 同時i++,這時就會 race condition
Solution
加鎖
thread 之間是互相信任的,所以他們之間共用了很多資源(像是 heap、file descriptor…),但是這樣當兩個 thread 同時存取同塊記憶體,就可能造成 race condition
像是兩個 thread 同時i++,這時就會 race condition
加鎖