class_mutex.rst 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/4.0/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.0/doc/classes/Mutex.xml.
  6. .. _class_Mutex:
  7. Mutex
  8. =====
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. A binary :ref:`Semaphore<class_Semaphore>` for synchronization of multiple :ref:`Thread<class_Thread>`\ s.
  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. - :doc:`Thread-safe APIs <../tutorials/performance/thread_safe_apis>`
  20. .. rst-class:: classref-reftable-group
  21. Methods
  22. -------
  23. .. table::
  24. :widths: auto
  25. +-------------------------+----------------------------------------------------------+
  26. | void | :ref:`lock<class_Mutex_method_lock>` **(** **)** |
  27. +-------------------------+----------------------------------------------------------+
  28. | :ref:`bool<class_bool>` | :ref:`try_lock<class_Mutex_method_try_lock>` **(** **)** |
  29. +-------------------------+----------------------------------------------------------+
  30. | void | :ref:`unlock<class_Mutex_method_unlock>` **(** **)** |
  31. +-------------------------+----------------------------------------------------------+
  32. .. rst-class:: classref-section-separator
  33. ----
  34. .. rst-class:: classref-descriptions-group
  35. Method Descriptions
  36. -------------------
  37. .. _class_Mutex_method_lock:
  38. .. rst-class:: classref-method
  39. void **lock** **(** **)**
  40. Locks this **Mutex**, blocks until it is unlocked by the current owner.
  41. \ **Note:** This function returns without blocking if the thread already has ownership of the mutex.
  42. .. rst-class:: classref-item-separator
  43. ----
  44. .. _class_Mutex_method_try_lock:
  45. .. rst-class:: classref-method
  46. :ref:`bool<class_bool>` **try_lock** **(** **)**
  47. Tries locking this **Mutex**, but does not block. Returns ``true`` on success, ``false`` otherwise.
  48. \ **Note:** This function returns ``true`` if the thread already has ownership of the mutex.
  49. .. rst-class:: classref-item-separator
  50. ----
  51. .. _class_Mutex_method_unlock:
  52. .. rst-class:: classref-method
  53. void **unlock** **(** **)**
  54. Unlocks this **Mutex**, leaving it to other threads.
  55. \ **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.
  56. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  57. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  58. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  59. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  60. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  61. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`