当前位置:网站首页>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 .
边栏推荐
- Drawing dynamic 3D circle with pure C language
- [转]MySQL操作实战(三):表联结
- The present is a gift from heaven -- a film review of the journey of the soul
- Web APIs DOM节点
- Under the national teacher qualification certificate in the first half of 2022
- [turn]: Apache Felix framework configuration properties
- 2022年上半年国家教师资格证考试
- Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
- [es practice] use the native realm security mode on es
- Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
猜你喜欢
![[turn to] MySQL operation practice (I): Keywords & functions](/img/b1/8b843014f365b786e310718f669043.png)
[turn to] MySQL operation practice (I): Keywords & functions
![[speed pointer] 142 circular linked list II](/img/f8/222a360c01d8ef120b61bdd2025044.jpg)
[speed pointer] 142 circular linked list II

TF-A中的工具介绍

质量体系建设之路的分分合合

Double pointer Foundation

Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!

Ue4/ue5 illusory engine, material part (III), material optimization at different distances

sync.Mutex源码解读

National teacher qualification examination in the first half of 2022

Fragment addition failed error lookup
随机推荐
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
Haut OJ 1245: large factorial of CDs --- high precision factorial
PMP考生,请查收7月PMP考试注意事项
C language Essay 1
Zzulioj 1673: b: clever characters???
[to be continued] [depth first search] 547 Number of provinces
使用Room数据库报警告: Schema export directory is not provided to the annotation processor so we cannot expor
Stm32cubemx (8): RTC and RTC wake-up interrupt
Add level control and logger level control of Solon logging plug-in
ssh免密登录设置及使用脚本进行ssh登录并执行指令
第六章 数据流建模—课后习题
【ES实战】ES上的native realm安全方式使用
[turn to] MySQL operation practice (III): table connection
Pointnet++学习
[binary search] 34 Find the first and last positions of elements in a sorted array
Haut OJ 1401: praise energy
Find a good teaching video for Solon framework test (Solon, lightweight application development framework)
Haut OJ 1218: maximum continuous sub segment sum
The next key of win generates the timestamp file of the current day
[leetcode] integer inversion [7]