当前位置:网站首页>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 .
边栏推荐
- C language Essay 1
- [es practice] use the native realm security mode on es
- Web APIs DOM node
- Reverse one-way linked list of interview questions
- 浅谈JVM(面试常考)
- PMP考试敏捷占比有多少?解疑
- Haut OJ 1243: simple mathematical problems
- PMP candidates, please check the precautions for PMP examination in July
- Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
- On-off and on-off of quality system construction
猜你喜欢
[转]: OSGI规范 深入浅出
Heap sort summary
To the distance we have been looking for -- film review of "flying house journey"
win10虚拟机集群优化方案
挂起等待锁 vs 自旋锁(两者的使用场合)
小程序直播+电商,想做新零售电商就用它吧!
服务熔断 Hystrix
[to be continued] [UE4 notes] L2 interface introduction
Embedded database development programming (VI) -- C API
[turn to] MySQL operation practice (I): Keywords & functions
随机推荐
Programmers' experience of delivering takeout
Support multi-mode polymorphic gbase 8C database continuous innovation and heavy upgrade
FVP和Juno平台的Memory Layout介绍
Haut OJ 1218: maximum continuous sub segment sum
读者写者模型
Solon Logging 插件的添加器级别控制和日志器的级别控制
PMP考试敏捷占比有多少?解疑
TF-A中的工具介绍
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
Haut OJ 1243: simple mathematical problems
Simple HelloWorld color change
Use of snippets in vscode (code template)
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
A preliminary study of sdei - see the essence through transactions
PMP考生,请查收7月PMP考试注意事项
[merge array] 88 merge two ordered arrays
BUUCTF MISC
Use of room database
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
[turn to] MySQL operation practice (I): Keywords & functions