当前位置:网站首页>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 .
边栏推荐
- Haut OJ 1316: sister choice buys candy III
- Ue4/ue5 illusory engine, material part (III), material optimization at different distances
- [allocation problem] 135 Distribute candy
- [turn]: OSGi specification in simple terms
- Quick sort summary
- Acwing 4301. Truncated sequence
- Download xftp7 and xshell7 (official website)
- Research on the value of background repeat of background tiling
- FVP和Juno平台的Memory Layout介绍
- Generate filled text and pictures
猜你喜欢

Do a small pressure test with JMeter tool

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

十年不用一次的JVM调用

服务熔断 Hystrix

The present is a gift from heaven -- a film review of the journey of the soul
![[to be continued] [depth first search] 547 Number of provinces](/img/c4/b4ee3d936776dafc15ac275d2059cd.jpg)
[to be continued] [depth first search] 547 Number of provinces

To the distance we have been looking for -- film review of "flying house journey"

Romance of programmers on Valentine's Day

Research on the value of background repeat of background tiling
![[to be continued] [UE4 notes] L1 create and configure items](/img/20/54ba719be2e51b7db5b7645b361e26.jpg)
[to be continued] [UE4 notes] L1 create and configure items
随机推荐
[转]: OSGI规范 深入浅出
Research on the value of background repeat of background tiling
[转]MySQL操作实战(一):关键字 & 函数
UE fantasy engine, project structure
Collapse of adjacent vertical outer margins
Development error notes
Romance of programmers on Valentine's Day
Merge sort
Double pointer Foundation
YOLOv5-Shufflenetv2
Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
Shell Sort
[interval problem] 435 Non overlapping interval
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
2022上半年全国教师资格证下
Warning using room database: schema export directory is not provided to the annotation processor so we cannot export
Haut OJ 1401: praise energy
搭建完数据库和网站后.打开app测试时候显示服务器正在维护.
Heap sort summary
[轉]: OSGI規範 深入淺出