当前位置:网站首页>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 .
边栏推荐
- 软件测试 -- 0 序
- Demonstration of using Solon auth authentication framework (simpler authentication framework)
- [binary search] 34 Find the first and last positions of elements in a sorted array
- Es module and commonjs learning notes
- Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
- 利用HashMap实现简单缓存
- Web APIs DOM节点
- [to be continued] [UE4 notes] L1 create and configure items
- Use of room database
- Haut OJ 1243: simple mathematical problems
猜你喜欢
Stm32cubemx (8): RTC and RTC wake-up interrupt
The present is a gift from heaven -- a film review of the journey of the soul
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
[转]: OSGI规范 深入浅出
YOLOv5添加注意力機制
Heap sort summary
[to be continued] [depth first search] 547 Number of provinces
Magnifying glass effect
读者写者模型
Yolov5 ajouter un mécanisme d'attention
随机推荐
Zzulioj 1673: b: clever characters???
Drawing dynamic 3D circle with pure C language
C语言杂谈1
Research on the value of background repeat of background tiling
Simple modal box
MySQL数据库(一)
2022/7/1 learning summary
Demonstration of using Solon auth authentication framework (simpler authentication framework)
质量体系建设之路的分分合合
Haut OJ 1241: League activities of class XXX
[binary search] 34 Find the first and last positions of elements in a sorted array
一个新的微型ORM开源框架
win10虚拟机集群优化方案
Bucket sort
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
Use of snippets in vscode (code template)
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
Summary of Haut OJ 2021 freshman week
Transport connection management of TCP