当前位置:网站首页>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 .
边栏推荐
- 2022/7/1學習總結
- SDEI初探-透过事务看本质
- How can the Solon framework easily obtain the response time of each request?
- Collapse of adjacent vertical outer margins
- PMP考生,请查收7月PMP考试注意事项
- Embedded database development programming (VI) -- C API
- Haut OJ 1347: addition of choice -- high progress addition
- 十年不用一次的JVM调用
- [turn to] MySQL operation practice (III): table connection
- 2022 / 7 / 1 Résumé de l'étude
猜你喜欢
远程升级怕截胡?详解FOTA安全升级
Shell Sort
Research on the value of background repeat of background tiling
To the distance we have been looking for -- film review of "flying house journey"
Merge sort
UE fantasy engine, project structure
A new micro ORM open source framework
Gbase database helps the development of digital finance in the Bay Area
[to be continued] [UE4 notes] L1 create and configure items
[turn to] MySQL operation practice (III): table connection
随机推荐
YOLOv5添加注意力機制
Bucket sort
Haut OJ 1243: simple mathematical problems
一个新的微型ORM开源框架
Haut OJ 1352: string of choice
Demonstration of using Solon auth authentication framework (simpler authentication framework)
读者写者模型
Heap sort summary
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
Reflection summary of Haut OJ freshmen on Wednesday
Collapse of adjacent vertical outer margins
Haut OJ 1241: League activities of class XXX
[turn]: OSGi specification in simple terms
The present is a gift from heaven -- a film review of the journey of the soul
[轉]: OSGI規範 深入淺出
sync.Mutex源码解读
Development error notes
YOLOv5-Shufflenetv2
Pointnet++的改进
Haut OJ 1245: large factorial of CDs --- high precision factorial