lock.acquire 是否阻塞非临界区中的进程
Does lock.acquire blocks processes in non critical section
也许我没有很好地阅读文档,但我没有找到有关 lock 或 rlock 的 aquire 如何工作的更多信息......它是否阻止所有进程,无论这些进程在什么语句上(即使它们不在关键部分).. 还是只阻止试图访问关键部分的进程
谢谢!
来自文档:
class multiprocessing.Lock
A non-recursive lock object: a close analog of threading.Lock. Once a process or thread has acquired a lock, subsequent attempts to acquire it from any process or thread will block until it is released; any process or thread may release it. The concepts and behaviors of threading.Lock as it applies to threads are replicated here in multiprocessing.Lock as it applies to either processes or threads, except as noted.
因此,当您调用 acquire()
(注意 block
参数使用默认值)时,您的过程将:
- 如果处于解锁状态,则获取锁。
- 阻塞直到锁处于解锁状态,然后获取它。
此机制允许您在逻辑中定义 "critical sections",这意味着一次只有一个进程将执行该特定功能(即播放音频文件)
也许我没有很好地阅读文档,但我没有找到有关 lock 或 rlock 的 aquire 如何工作的更多信息......它是否阻止所有进程,无论这些进程在什么语句上(即使它们不在关键部分).. 还是只阻止试图访问关键部分的进程
谢谢!
来自文档:
class
multiprocessing.Lock
A non-recursive lock object: a close analog of threading.Lock. Once a process or thread has acquired a lock, subsequent attempts to acquire it from any process or thread will block until it is released; any process or thread may release it. The concepts and behaviors of threading.Lock as it applies to threads are replicated here in multiprocessing.Lock as it applies to either processes or threads, except as noted.
因此,当您调用 acquire()
(注意 block
参数使用默认值)时,您的过程将:
- 如果处于解锁状态,则获取锁。
- 阻塞直到锁处于解锁状态,然后获取它。
此机制允许您在逻辑中定义 "critical sections",这意味着一次只有一个进程将执行该特定功能(即播放音频文件)