当前位置:网站首页>LockSupport. Park and unpark, wait and notify
LockSupport. Park and unpark, wait and notify
2022-04-23 06:21:00 【commonBean】
LockSupport.park Method to block the current thread ,unpark You can resume its operation .
LockSupport And every thread that uses it has a license (permit) relation .permit amount to 1,0 The switch of , The default is 0, Call once unpark Just add 1 become 1, Call once park Will be spending permit, Also is to 1 become 0, meanwhile park Return immediately . Call again park Will become block( because permit by 0 了 , It's going to get stuck here , until permit Turn into 1), Call at this time unpark Will be able to permit Set as 1. Each thread has an associated permit, permit At most one , Repeated calls to unpark It won't accumulate .
park()/unpark() The underlying principle is “ Binary semaphore ”, You can think of it as if it had only one license Semaphore, But this semaphore is executing repeatedly unpark() There will be no more licenses , There is only one license at most .
Before one of the following three situations occurs , The current thread will be dormant :
- Some other thread calls... With the current thread as the target unpark.
- Another thread interrupts the current thread .
- The call illogically ( That is, without any reason ) return .
Thread.sleep() Will not release the lock of possession ,LockSupport.park() The lock held by the current thread will not be released ;Object.wait() Will release the lock of possession .
Thread.sleep() Time must be passed in , Can't wake up from the outside , I can only wake up myself ;Object.wait() Can pass but not pass , With time , If not notify, It will wake up automatically when it's time , No transmission means it's stuck , Need another thread to use Object.notify() Wake up the ;LockSupport.park() Method can be called by another thread LockSupport.unpark() Method wake up ;
If in wait() It was done before notify() Will throw out IllegalMonitorStateException abnormal ; If in park() It was done before unpark(), Threads will not be blocked , Just skip park(), Continue with what follows ;
版权声明
本文为[commonBean]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220533052852.html
边栏推荐
- Fundamentals of digital image processing (Gonzalez) II: gray transformation and spatial filtering
- How to grow at work
- 深入理解去噪论文——FFDNet和CBDNet中noise level与噪声方差之间的关系探索
- 9.Life, the Universe, and Everything
- Treatment of tensorflow sequelae - simple example record torch utils. data. dataset. Picture dimension problem when rewriting dataset
- Pytorch notes - get familiar with the network construction method by building RESNET (complete code)
- Collections multiple parameter sorting
- Linear algebra Chapter 2 - matrices and their operations
- Delete and truncate
- 1. Calculate a + B
猜你喜欢
线性代数第一章-行列式
Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images
Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots
Pytorch notes - observe dataloader & build lenet with torch to process cifar-10 complete code
SQL injection
Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
Algèbre linéaire chapitre 1 - déterminants
Fundamentals of digital image processing (Gonzalez) II: gray transformation and spatial filtering
String notes
On traversal of binary tree
随机推荐
A sharp tool to improve work efficiency
图像恢复论文简记——Uformer: A General U-Shaped Transformer for Image Restoration
Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising
Chapter 4 of line generation - linear correlation of vector systems
Treatment of tensorflow sequelae - simple example record torch utils. data. dataset. Picture dimension problem when rewriting dataset
Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
3. Continuous integer
1. Calculate a + B
Pytorch introduction notes - use a simple example to observe the output size of each layer of forward propagation
Example of ticket selling with reentrant lock
sklearn之 Gaussian Processes
MySQL basic madness theory
Create enterprise mailbox account command
Solve the error: importerror: iprogress not found Please update jupyter and ipywidgets
深入理解去噪论文——FFDNet和CBDNet中noise level与噪声方差之间的关系探索
如何利用对比学习做无监督——[CVPR22]Deraining&[ECCV20]Image Translation
Numpy common function table sorting of data processing
RedHat realizes keyword search in specific text types under the directory and keyword search under VIM mode
常用编程记录——parser = argparse.ArgumentParser()
Use Matplotlib. In Jupiter notebook Pyplot server hangs up and crashes