当前位置:网站首页>临界区(critical section 每个线程中访问 临界资源 的那段代码)和互斥锁(mutex)的区别(进程间互斥量、共享内存、虚拟地址)
临界区(critical section 每个线程中访问 临界资源 的那段代码)和互斥锁(mutex)的区别(进程间互斥量、共享内存、虚拟地址)
2022-07-27 06:12:00 【Dontla】
今天看这篇文章,感觉临界区和互斥锁效果差不多,都是锁住一段代码,只让一个线程访问,不知道有什么区别。。。
C语言多线程基础-02-临界区,互斥量
区别:
1、临界区只能用于对象在同一进程里线程间的互斥访问;互斥体可以用于对象进程间或线程间的互斥访问。
2、临界区是非内核对象,只在用户态进行锁操作,速度快;互斥体是内核对象,在核心态进行锁操作,速度慢。
3、临界区和互斥体在Windows平台都下可用;Linux下只有互斥体可用(Linux下只能用锁)
参考文章:临界区和互斥锁的区别
关于进程间的互斥体(互斥锁),我不太明白,可以参考这篇文章:
它是用共享内存的方式实现的,在调用pthread_mutex_init()函数时,第二个参数需要传入一个属性对象(状态对象)的地址
而锁需要定义在共享内存上,关于共享内存的创建,可以参考这篇文章:
Linux共享内存 封装
另外,可见补充知识:
LINUX进程变量隔离 虚拟地址
边栏推荐
- 想sink 到 redis-hash 里面 把 对象的属性和值都写进去 ,大佬们有Demo 吗?
- 12. Integer to Roman整数转罗马数字
- tableau prep连接maxcompute,只是书写很简单的sql,为啥报这个错误呢?
- Oracle 组合查询
- Digital image processing -- Chapter 3 gray scale transformation and spatial filtering
- flink cdc 抽取oracle的数据,会不断的占用oracle的内存吗,最后引发ora-040
- Es compares the data difference between the two indexes
- 35. Search insert position
- VIM editor deletes all file contents
- “蔚来杯“2022牛客暑期多校训练营1
猜你喜欢

Esp8266 (esp-12f) third party library use -- sparkfun_ Apds9960 (gesture recognition)

How to implement Devops with automation tools | including low code and Devops application practice

Jmeter: interface automation test - BeanShell compares database data and return data

Drools(5):Drools高级语法

Visual horizontal topic bug1:filenotfounderror: could not find module 'mvcameracontrol dll‘ (or one of it

Jmeter:接口自动化测试-BeanShell对数据库数据和返回数据比较

零号培训平台课程-1、SQL注入基础

零号培训平台课程-2、SSRF基础

No.0 training platform course-2. SSRF Foundation

多线程【初阶-上篇】
随机推荐
Drools (5): drools advanced syntax
如何取得对象的DDL信息
Excuse me, is there a big delay in individual capture when someone uses Oracle xStream? How to solve the delay problem
A Competitive Swarm Optimizer for Large Scale Optimization
Es compares the data difference between the two indexes
Which C4d cloud rendering platform to cooperate with?
Please ask the big guys a question. The pgsqlcdc task can't monitor changes after running for a period of time. Just restart it. What should I do
Generics -- learn it, and there are many benefits
2021 interview question of php+go for Zhongda factory (1)
Watermelon book chapter 3 - linear model learning notes
指令集 x 数澜科技丨加速政企数字化转型,打造DT领域独角兽企业联盟
Codeforces Round #804 (Div. 2)(5/5)
yhb_sysbench
查看服务器重启前的 dmesg 日志
Firefox browser, when accessing Tencent cloud server, failed to establish a secure connection.
py2exe qt界面风格变成了win98解决方案
ShowDoc漏洞学习——CNVD-2020-26585(任意文件上传)
Misunderstanding of slice slice in golang
(转帖)eureka、consul、nacos的对比2
Drools(5):Drools基础语法(3)