当前位置:网站首页>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
边栏推荐
- Get the value of state in effects in DVA
- @Problems caused by internal dead loop of postconstruct method
- Use of multithreaded executors
- 5.The Simple Problem
- Why does the subscript of the array start from 0 instead of 1?
- 在Jupyter notebook中用matplotlib.pyplot出现服务器挂掉、崩溃的问题
- Fact final variable and final variable
- Unsupervised denoising - [tmi2022] ISCL: dependent self cooperative learning for unpaired image denoising
- Pytorch introduction notes - use a simple example to observe the output size of each layer of forward propagation
- Fundamentals of digital image processing (Gonzalez) II: gray transformation and spatial filtering
猜你喜欢

20 excellent plug-ins recommended by idea

CONDA virtual environment management (create, delete, clone, rename, export and import)

Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.

Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)

container

Pytorch——数据加载和处理

Pytoch -- data loading and processing

Filebrowser realizes private network disk

深入理解去噪论文——FFDNet和CBDNet中noise level与噪声方差之间的关系探索

Anaconda installed pyqt5 and pyqt5 tools without designer Exe problem solving
随机推荐
sklearn之 Gaussian Processes
Common programming records - parser = argparse ArgumentParser()
Pytorch learning record (III): structure of neural network + using sequential and module to define the model
Three ways to create threads
Anaconda安装PyQt5 和 pyqt5-tools后没有出现designer.exe的问题解决
JDBC connection database
The problem that the page will refresh automatically after clicking the submit button on the form is solved
Kibana search syntax
1. Calculate a + B
Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)
How to use comparative learning to do unsupervised - [cvpr22] training & [eccv20] image translation
PyTorch入门小笔记——利用简单例子观察前向传播各个层输出的size
Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising
[transfer] MySQL: how many rows of data can InnoDB store in a B + tree?
EditorConfig
线代第四章-向量组的线性相关
Collections multiple parameter sorting
How does MySQL convert stored seconds into dates
Create binary tree
You cannot access this shared folder because your organization's security policy prevents unauthenticated guests from accessing it