linux多线程学习(六)——信号量实现同步
来源:互联网 发布:医疗器械国家数据库 编辑:程序博客网 时间:2024/06/06 19:37
信号量的互斥同步都是通过PV原语来操作的,我们可以通过注册两个信号量,让它们在互斥的问题上互动,从而达到同步。通过下面实例就可以很容易理解:
pthread2: pthread2 get the unlock.
pthread2: pthread2 unlock.
pthread1: pthread1 get the lock.
pthread1: pthread1 unlock
pthread2: pthread2 get the unlock.
pthread2: pthread2 unlock.
pthread1: pthread1 get the lock.
pthread1: pthread1 unlock
pthread2: pthread2 get the unlock.
pthread2: pthread2 unlock.
pthread1: pthread1 get the lock.
pthread1: pthread1 unlock
pthread2: pthread2 get the unlock.
pthread2: pthread2 unlock.
pthread1: pthread1 get the lock.
pthread1: pthread1 unlock
pthread2: pthread2 get the unlock.
pthread2: pthread2 unlock.
pthread1: pthread1 get the lock.
pthread1: pthread1 unlock
pthread2: pthread2 get the unlock.
pthread2: pthread2 unlock.
pthread1: pthread1 get the lock.
pthread1: pthread1 unlock
pthread2: pthread2 get the unlock.
pthread2: pthread2 unlock.
pthread1: pthread1 get the lock.
pthread1: pthread1 unlock
pthread2: pthread2 get the unlock.
pthread2: pthread2 unlock.
pthread1: pthread1 get the lock.
pthread1: pthread1 unlock
pthread2: pthread2 get the unlock.
pthread2: pthread2 unlock.
pthread1: pthread1 get the lock.
pthread1: pthread1 unlock
pthread2: pthread2 get the unlock.
pthread2: pthread2 unlock.
pthread1: pthread1 get the lock.
pthread1: pthread1 unlock
通过执行结果后,可以看出,会先执行线程二的函数,然后再执行线程一的函数。它们两就实现了同步。在上大学的时候,虽然对这些概念知道,可都没有实践过,所以有时候时间一久就会模糊甚至忘记,到了工作如果还保持这么一种状态,那就太可怕了。虽然现在外面的技术在不断的变化更新,可是不管怎么变,其核心技术还是依旧的,所以我们必须要打好自己的基础,再学习其他新的知识,那时候再学新的知识也会觉得比较简单的。闲话多说了两句,在下一篇文章中,我们将会实现一个经典的实例回顾这段时间对多线程的学习,那就是消费者和生产者。
- linux多线程学习(六)——信号量实现同步。
- linux多线程学习(六)——信号量实现同步
- linux多线程学习(六)——信号量实现同步。
- linux多线程学习(六)——信号量实现同步
- linux多线程学习(六)——信号量实现同步
- linux多线程学习(六)——信号量实现同步。
- linux多线程学习(六)——信号量实现同步
- linux多线程学习(六)——信号量实现同步
- Linux多线程同步——信号量
- 【Linux】 多线程编程(信号量实现同步)
- 操作系统(Linux)多线程--信号量实现同步
- 多线程同步——信号量
- Linux多线程——使用信号量同步线程
- Linux多线程——使用信号量同步线程
- Linux多线程——使用信号量同步线程
- Linux多线程——使用信号量同步线程
- Linux多线程——使用信号量同步线程
- Linux多线程——使用信号量同步线程
- android studio配置butterknife 8.0以上版本
- HTML5学习笔记(零)
- 添加Action 按钮
- ssh三大框架整合--jar包
- Redux系列01:从一个简单例子了解action、store、reducer
- linux多线程学习(六)——信号量实现同步
- Construct Binary Tree from Inorder and Postorder Traversal
- jvm笔记4--类文件结构
- leetcode 35. Search Insert Position
- Filter高级开发(三)——压缩响应正文内容
- GL_CLAMP GL_CLAMP_TO_EDGE GL_CLAMP_TO_BORDER
- Caffe 初学拾遗(四) CUDA 框架说明
- JSON 对象与字符串相互转换
- ural 1306 (heap推排序)