class_mutex.rst 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. Description
  12. -----------
  13. 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.
  14. Tutorials
  15. ---------
  16. - :doc:`Using multiple threads <../tutorials/performance/using_multiple_threads>`
  17. Methods
  18. -------
  19. +---------------------------------------+----------------------------------------------------------+
  20. | void | :ref:`lock<class_Mutex_method_lock>` **(** **)** |
  21. +---------------------------------------+----------------------------------------------------------+
  22. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`try_lock<class_Mutex_method_try_lock>` **(** **)** |
  23. +---------------------------------------+----------------------------------------------------------+
  24. | void | :ref:`unlock<class_Mutex_method_unlock>` **(** **)** |
  25. +---------------------------------------+----------------------------------------------------------+
  26. Method Descriptions
  27. -------------------
  28. .. _class_Mutex_method_lock:
  29. - void **lock** **(** **)**
  30. Locks this ``Mutex``, blocks until it is unlocked by the current owner.
  31. \ **Note:** This function returns without blocking if the thread already has ownership of the mutex.
  32. ----
  33. .. _class_Mutex_method_try_lock:
  34. - :ref:`Error<enum_@GlobalScope_Error>` **try_lock** **(** **)**
  35. 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.
  36. \ **Note:** This function returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` if the thread already has ownership of the mutex.
  37. ----
  38. .. _class_Mutex_method_unlock:
  39. - void **unlock** **(** **)**
  40. Unlocks this ``Mutex``, leaving it to other threads.
  41. \ **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.
  42. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  43. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  44. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  45. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  46. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  47. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`