Mutex.xml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="Mutex" inherits="RefCounted" version="4.0">
  3. <brief_description>
  4. A synchronization mutex (mutual exclusion).
  5. </brief_description>
  6. <description>
  7. A synchronization mutex (mutual exclusion). This is used to synchronize multiple [Thread]s, and is equivalent to a binary [Semaphore]. It guarantees that only one thread can ever acquire the lock at a time. A mutex can be used to protect a critical section; however, be careful to avoid deadlocks.
  8. </description>
  9. <tutorials>
  10. <link title="Using multiple threads">https://docs.godotengine.org/en/latest/tutorials/performance/using_multiple_threads.html</link>
  11. </tutorials>
  12. <methods>
  13. <method name="lock">
  14. <return type="void" />
  15. <description>
  16. Locks this [Mutex], blocks until it is unlocked by the current owner.
  17. [b]Note:[/b] This function returns without blocking if the thread already has ownership of the mutex.
  18. </description>
  19. </method>
  20. <method name="try_lock">
  21. <return type="int" enum="Error" />
  22. <description>
  23. Tries locking this [Mutex], but does not block. Returns [constant OK] on success, [constant ERR_BUSY] otherwise.
  24. [b]Note:[/b] This function returns [constant OK] if the thread already has ownership of the mutex.
  25. </description>
  26. </method>
  27. <method name="unlock">
  28. <return type="void" />
  29. <description>
  30. Unlocks this [Mutex], leaving it to other threads.
  31. [b]Note:[/b] If a thread called [method lock] or [method try_lock] multiple times while already having ownership of the mutex, it must also call [method unlock] the same number of times in order to unlock it correctly.
  32. </description>
  33. </method>
  34. </methods>
  35. </class>