Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Semaphore
繼承: RefCounted < Object
同步機制,用於控制對 Thread 之間共用資源的存取。
說明
同步機制,用於控制對 Thread 之間共用資源的存取。建立時初始化為零。二元版本見 Mutex。
警告:訊號量必須謹慎使用,防止鎖死。
警告:為了確保作業系統能夠執行正確的清理(避免當機和思索),必須滿足以下條件:
Semaphore 的引用計數變為零,導致銷毀時,沒有執行緒在等待該訊號量。
Thread 的引用計數變為零,導致銷毀時,沒有在等待任何訊號量。
教學
方法
void |
|
try_wait() |
|
void |
wait() |
方法說明
Lowers the Semaphore, allowing one thread in, or more if count is specified.
與 wait() 類似,但不會阻塞,所以如果值為零,則會立即失敗並返回 false。如果非零,則返回 true 以報告成功。
void wait() 🔗
等待該 Semaphore,如果它的值為零,則阻塞到變為非零為止。