自旋锁适用于短时间等待线程的场景;
- #include
- //初始化
- int pthread_spin_init(pthread_spinlock_t *lock, int pshared);
- //销毁
- int pthread_spin_destroy(pthread_spinlock_t *lock);
-
-
- //加锁,轮询;
- int pthread_spin_lock(pthread_spinlock_t *lock);
-
- //加锁,申请不到直接返回;
- int pthread_spin_trylock(pthread_spinlock_t *lock);
-
-
- //解锁
- int pthread_spin_unlock(pthread_spinlock_t *lock);
-
-
-