class_mutex.rst 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Mutex.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Mutex:
  6. Mutex
  7. =====
  8. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. A synchronization mutex (mutual exclusion).
  10. Description
  11. -----------
  12. A synchronization mutex (mutual exclusion). This is used to synchronize multiple :ref:`Thread<class_Thread>`\ s, and is equivalent to a binary :ref:`Semaphore<class_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.
  13. Tutorials
  14. ---------
  15. - :doc:`../tutorials/performance/threads/using_multiple_threads`
  16. Methods
  17. -------
  18. +---------------------------------------+----------------------------------------------------------+
  19. | void | :ref:`lock<class_Mutex_method_lock>` **(** **)** |
  20. +---------------------------------------+----------------------------------------------------------+
  21. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`try_lock<class_Mutex_method_try_lock>` **(** **)** |
  22. +---------------------------------------+----------------------------------------------------------+
  23. | void | :ref:`unlock<class_Mutex_method_unlock>` **(** **)** |
  24. +---------------------------------------+----------------------------------------------------------+
  25. Method Descriptions
  26. -------------------
  27. .. _class_Mutex_method_lock:
  28. - void **lock** **(** **)**
  29. Locks this ``Mutex``, blocks until it is unlocked by the current owner.
  30. **Note:** This function returns without blocking if the thread already has ownership of the mutex.
  31. ----
  32. .. _class_Mutex_method_try_lock:
  33. - :ref:`Error<enum_@GlobalScope_Error>` **try_lock** **(** **)**
  34. Tries locking this ``Mutex``, but does not block. Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success, :ref:`@GlobalScope.ERR_BUSY<class_@GlobalScope_constant_ERR_BUSY>` otherwise.
  35. **Note:** This function returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` if the thread already has ownership of the mutex.
  36. ----
  37. .. _class_Mutex_method_unlock:
  38. - void **unlock** **(** **)**
  39. Unlocks this ``Mutex``, leaving it to other threads.
  40. **Note:** If a thread called :ref:`lock<class_Mutex_method_lock>` or :ref:`try_lock<class_Mutex_method_try_lock>` multiple times while already having ownership of the mutex, it must also call :ref:`unlock<class_Mutex_method_unlock>` the same number of times in order to unlock it correctly.
  41. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  42. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  43. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`