POSIX 之互斥锁(mutex)、互斥锁属性

Gaia ·
更新时间:2024-11-13
· 723 次阅读

POSIX 之互斥锁(mutex)、互斥锁属性 0 引言

在多线程程序设计时不可避免地会遇到线程同步问题,最常用的操作就是进行加锁,通过加锁来保证数据的准确性,在所有加锁方式中最简单、最常用也就是mutex锁,本博文将详细介绍posix mutex的使用,本文主要内容:

Mutex Synchronization APIs Mutex Attributes 1 Mutex 1.1 Mutex Manage APIs List Table

Mutex 比较简单,锁的状态只有两种:加锁 解锁,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
1.2 APIs详解 1.2.1 pthread_mutex_init和pthread_mutex_destroy。。。。。。详解介绍各个api的具体用法 以及在Linux和VxWorks下的不同 。。。。。。。。。。 2 Mutex Attributes 2.1 Mutex Attributes APIs List Table
函数 描述 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
2.2 APIs详解 2.2.1 pthread_mutexattr_init() pthread_mutexattr_destroy()

。。。。。。


作者:码中飞翔



posix 属性 互斥 互斥锁

需要 登录 后方可回复, 如果你还没有账号请 注册新账号