class_mutex.rst 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.5/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.5/doc/classes/Mutex.xml.
  6. .. _class_Mutex:
  7. Mutex
  8. =====
  9. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. A synchronization mutex (mutual exclusion).
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. 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.
  15. .. rst-class:: classref-introduction-group
  16. Tutorials
  17. ---------
  18. - :doc:`../tutorials/performance/threads/using_multiple_threads`
  19. .. rst-class:: classref-reftable-group
  20. Methods
  21. -------
  22. .. table::
  23. :widths: auto
  24. +---------------------------------------+----------------------------------------------------------+
  25. | void | :ref:`lock<class_Mutex_method_lock>` **(** **)** |
  26. +---------------------------------------+----------------------------------------------------------+
  27. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`try_lock<class_Mutex_method_try_lock>` **(** **)** |
  28. +---------------------------------------+----------------------------------------------------------+
  29. | void | :ref:`unlock<class_Mutex_method_unlock>` **(** **)** |
  30. +---------------------------------------+----------------------------------------------------------+
  31. .. rst-class:: classref-section-separator
  32. ----
  33. .. rst-class:: classref-descriptions-group
  34. Method Descriptions
  35. -------------------
  36. .. _class_Mutex_method_lock:
  37. .. rst-class:: classref-method
  38. void **lock** **(** **)**
  39. Locks this **Mutex**, blocks until it is unlocked by the current owner.
  40. \ **Note:** This function returns without blocking if the thread already has ownership of the mutex.
  41. .. rst-class:: classref-item-separator
  42. ----
  43. .. _class_Mutex_method_try_lock:
  44. .. rst-class:: classref-method
  45. :ref:`Error<enum_@GlobalScope_Error>` **try_lock** **(** **)**
  46. 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.
  47. \ **Note:** This function returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` if the thread already has ownership of the mutex.
  48. .. rst-class:: classref-item-separator
  49. ----
  50. .. _class_Mutex_method_unlock:
  51. .. rst-class:: classref-method
  52. void **unlock** **(** **)**
  53. Unlocks this **Mutex**, leaving it to other threads.
  54. \ **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.
  55. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  56. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  57. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  58. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`