使用pthread_mutex_t锁的例子
来源:互联网 发布:沙盘类似软件 编辑:程序博客网 时间:2024/05/16 02:04
posix下抽象了一个锁类型的结构:ptread_mutex_t。通过对该结构的操作,来判断资源是否可以访问。顾名思义,加锁(lock)后,别人就无法打开,只有当锁没有关闭(unlock)的时候才能访问资源。
最简单的用法:
pthread_mutex_t lock;//初始化锁变量&lock。第二个参数为锁属性,NULL值为默认属性。pthread_mutex_int(&lock, NULL);...//加锁pthread_mutex_lock(&lock);...//释放锁 pthread_mutex_unlock(&lock);...//使用完后释放 pthread_mutex_destroy(&lock);
pthread_mutex_tylock(pthread_mutex_t *mutex);加锁,但是与pthread_mutex_lock不一样的是当锁已经在使用的时候,返回为EBUSY,而不是挂起等待
0 0
- 使用pthread_mutex_t锁的例子
- 使用pthread_mutex_t锁的例子
- 使用pthread_mutex_t锁的例子
- 使用pthread_mutex_t锁的例子
- 使用pthread_mutex_t锁的例子
- 使用pthread_mutex_t锁的例子
- 互斥锁pthread_mutex_t的使用
- 互斥锁pthread_mutex_t的使用
- 互斥锁pthread_mutex_t的使用
- 互斥锁pthread_mutex_t的使用
- 互斥锁pthread_mutex_t的使用
- 互斥锁pthread_mutex_t的使用
- 互斥锁pthread_mutex_t的使用
- pthread_mutex_t的使用
- pthread_mutex_t的使用
- 互斥锁pthread_mutex_t的使用
- pthread_mutex_t的使用
- 互斥锁pthread_mutex_t的使用
- android中 页面间的无阻碍传值/接收值
- spring mvc修改的问题解决思路
- 响应Return键
- (4.5.2.1)Android Studio教程02-Hello Word
- Android表情文字EmotionText解析
- 使用pthread_mutex_t锁的例子
- 数据库分库分表(sharding)系列
- struts1与struts2的区别
- MySQL数据导出与导入
- Installing the License Key for SCOM 2012
- 最简单地实现标签页导航-----TabLayout+ViewPager
- linux ps命令
- (4.5.2.2)Android Studio教程03-项目目录以及文件的详解
- Java多级排序