2019-03-05  本文已影响0人  巴拉那

1.mutex

api:

pthread_mutex_lock

pthread_mutex_unlock

pthread_mutex_trylock

type:

#define PTHREAD_MUTEX_NORMAL      0

#define PTHREAD_MUTEX_ERRORCHECK  1

#define PTHREAD_MUTEX_RECURSIVE      2

In computer science, the reentrant mutex (recursive mutexrecursive lock) is particular type of mutual exclusion (mutex) device that may be locked multiple times by the same process/thread, without causing a deadlock.

#define PTHREAD_MUTEX_DEFAULT    PTHREAD_MUTEX_NORMAL

2.读写锁

PREFER_READER

PREFER_WRITER

https://cloud.tencent.com/developer/article/1087263

https://code.woboq.org/userspace/glibc/nptl/pthread_rwlock_common.c.html#__pthread_rwlock_rdlock_full

// TODO:把性能和读写mode的选择搞明白

3.condition

pthread_cond_wait

pthread_cond_timedwait

pthread_cond_signal

pthread_cond_broadcast

4.spin lock

互斥锁机制下,如果资源被占用,资源申请者就会进入睡眠状态。自旋则不是

-----

low level lock

https://code.woboq.org/userspace/glibc/sysdeps/unix/sysv/linux/sparc/lowlevellock.h.html

上一篇下一篇

猜你喜欢

热点阅读