class_mutex.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Mutex.xml.
  6. .. _class_Mutex:
  7. Mutex
  8. =====
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :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:`Using multiple threads <../tutorials/performance/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:`bool<class_bool>` | :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:`bool<class_bool>` **try_lock** **(** **)**
  46. Tries locking this **Mutex**, but does not block. Returns ``true`` on success, ``false`` 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. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  59. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  60. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`