lock: mutex/spinlock/shared lock

mutex( x lock): when a mutex lock is obtained, others cannot obtain the same mutex while the lock is not freed.

shared lock( s lock): when a shared lock is obtained, others can obtain the shared lock, but the mutex lock cannot be obtained while any one holding a shared lock. While holding the shared lock, only read data is permitted. One cannot write data while holding a shared lock.

spin lock: different kind of mutex, which implemented as keep trying to get the non-shared lock. (When trying to get the mutex, the thread might get switched out of the cpu(sleep), however the spin lock keeps running on the cpu.)

猜你喜欢

转载自www.cnblogs.com/sansna/p/9847103.html