当前位置:网站首页>Hang wait lock vs spin lock (where both are used)
Hang wait lock vs spin lock (where both are used)
2022-07-05 05:24:00 【abs(ln(1+NaN))】
1、 Definition of spin lock
Hang wait lock : When a thread does not apply for a lock , At this point, the thread will be suspended , That is, join the waiting queue and wait . When the lock is released , Will be awakened , Re compete for locks
spinlocks : When a thread does not apply for a lock , The thread will not be suspended , Instead, check whether the lock is released at regular intervals . If the lock is released , Then competition lock ; If not released , Check again later .
2、 Spin lock correlation function
Linux A data type is provided to represent spin lock —— pthread_spinlock_t
(1) Lock / Unlock function
(2) initialization / Destroy function
3、 Hang wait lock 、 Use scenario of spin lock
In that case , When should I use spin lock , When to use the pending lock ?
Example 1: You make an appointment with your friends to play basketball , Your friend said it would take an hour to get ready , So , You just went to the nearby Internet cafe for an hour to kill time .
Example 2: You also ask your friends to play basketball , Your friend said 5 Minutes ready , So you wait downstairs , every other 1 Minutes to send a message to your friend asking about the situation .
Example 1 ——》 Hang wait lock , When the critical zone operates for a long time , We usually use hang wait lock . Let's first let the thread PCB Join the waiting queue and wait , When the lock is released , Apply for the lock again .
Example 2 ——》 spinlocks , If you use a pending lock here , Maybe the thread just joined the waiting queue , The lock is released , It costs to wake up the thread . therefore , When the critical zone operates for a short time , We usually use spin lock .
边栏推荐
- [to be continued] I believe that everyone has the right to choose their own way of life - written in front of the art column
- 嵌入式数据库开发编程(五)——DQL
- On-off and on-off of quality system construction
- Drawing dynamic 3D circle with pure C language
- 动漫评分数据分析与可视化 与 IT行业招聘数据分析与可视化
- When will Wei Lai, who has been watched by public opinion, start to "build high-rise buildings" again?
- 嵌入式数据库开发编程(零)
- win下一键生成当日的时间戳文件
- Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
- Collapse of adjacent vertical outer margins
猜你喜欢
[interval problem] 435 Non overlapping interval
[turn to] MySQL operation practice (I): Keywords & functions
Heap sort summary
Introduction to tools in TF-A
Yolov5 ajouter un mécanisme d'attention
《动手学深度学习》学习笔记
Embedded database development programming (zero)
Acwing 4300. Two operations
Generate filled text and pictures
Bucket sort
随机推荐
Demonstration of using Solon auth authentication framework (simpler authentication framework)
TF-A中的工具介绍
Development error notes
PMP考生,请查收7月PMP考试注意事项
[binary search] 34 Find the first and last positions of elements in a sorted array
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
[allocation problem] 135 Distribute candy
Reverse one-way linked list of interview questions
2022 / 7 / 1 Résumé de l'étude
xftp7与xshell7下载(官网)
嵌入式数据库开发编程(六)——C API
Zheng Qing 21 ACM is fun. (3) part of the problem solution and summary
一个新的微型ORM开源框架
Haut OJ 1218: maximum continuous sub segment sum
Simple HelloWorld color change
[to be continued] I believe that everyone has the right to choose their own way of life - written in front of the art column
Haut OJ 1245: large factorial of CDs --- high precision factorial
Learning notes of "hands on learning in depth"
Haut OJ 1241: League activities of class XXX
Find a good teaching video for Solon framework test (Solon, lightweight application development framework)