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.)

posted on 2018-10-25 00:26  三叁  阅读(164)  评论(0编辑  收藏  举报

导航