在多线程程序设计时不可避免地会遇到线程同步问题,最常用的操作就是进行加锁,通过加锁来保证数据的准确性,在所有加锁方式中最简单、最常用也就是mutex锁,本博文将详细介绍posix mutex的使用,本文主要内容:
Mutex Synchronization APIs Mutex Attributes 1 Mutex 1.1 Mutex Manage APIs List TableMutex 比较简单,锁的状态只有两种:加锁 解锁,mutex主要的操作如下表:
函数 | 描述 | Linux | VxWorks | 备注 |
---|---|---|---|---|
pthread_mutex_init() | Initialize Mutex | support | support | |
pthread_mutex_destroy() | Destroy Mutex | support | support | |
pthread_mutex_lock() | Lock Mutex | support | support | |
pthread_mutex_unlock() | Unlock Mutex | support | support | |
pthread_mutex_trylock() | Lock Mutex with No Wait | support | support | |
pthread_mutex_timedlock_np() | Lock Mutex with Time-out | support | support | |
pthread_lock_global_np() | Lock a Global Mutex | support | support | |
pthread_unlock_global_np() | Unlock a Global Mutex | support | support |
函数 | 描述 | Linux | VxWorks | 备注 |
---|---|---|---|---|
pthread_mutexattr_init() | Initialize Mutex Attributes Object | support | support | |
pthread_mutexattr_destroy() | Destroy Mutex Attributes Object | support | support | |
pthread_mutexattr_getkind_np() | Get Mutex Kind Attribute | support | support | |
pthread_mutexattr_setkind_np() | Get Mutex Kind Attribute | support | support | |
pthread_mutexattr_getname_np() | Get Name from Mutex Attributes Object | support | support | |
pthread_mutexattr_setname_np() | Set Name in Mutex Attributes Object | support | support | |
pthread_mutexattr_getpshared() | Get Process Shared Attribute from Mutex Attributes Object | support | support | |
pthread_mutexattr_setpshared() | Set Process Shared Attribute in Mutex Attributes Object | support | support | |
pthread_mutexattr_gettype() | Get Mutex Type Attribute | support | support | |
pthread_mutexattr_settype() | Set Mutex Type Attribute | support | support | |
pthread_set_mutexattr_default_np() | Set Default Mutex Attributes Object Kind Attribute | support | support | |
pthread_mutexattr_getprioceiling() | Get Mutex Prioceiling Attribute | support | support | |
pthread_mutexattr_setprioceiling() | Set Mutex Prioceiling Attribute | support | support | |
pthread_mutexattr_getprotocol() | Get Mutex Protocol Attribute | support | support | |
pthread_mutexattr_setprotocol() | Set Mutex Protocol Attribute | support | support | |
pthread_mutex_getprioceiling() | Get Mutex Prioceiling | support | support | |
pthread_mutex_setprioceiling() | Set Mutex Prioceiling | support | support |
。。。。。。