class_semaphore.rst 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/Semaphore.xml.
  6. .. _class_Semaphore:
  7. Semaphore
  8. =========
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. A synchronization mechanism used to control access to a shared resource by :ref:`Thread<class_Thread>`\ s.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. A synchronization semaphore which can be used to synchronize multiple :ref:`Thread<class_Thread>`\ s. Initialized to zero on creation. Be careful to avoid deadlocks. For a binary version, see :ref:`Mutex<class_Mutex>`.
  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:`post<class_Semaphore_method_post>` **(** **)** |
  27. +-------------------------+--------------------------------------------------------------+
  28. | :ref:`bool<class_bool>` | :ref:`try_wait<class_Semaphore_method_try_wait>` **(** **)** |
  29. +-------------------------+--------------------------------------------------------------+
  30. | void | :ref:`wait<class_Semaphore_method_wait>` **(** **)** |
  31. +-------------------------+--------------------------------------------------------------+
  32. .. rst-class:: classref-section-separator
  33. ----
  34. .. rst-class:: classref-descriptions-group
  35. Method Descriptions
  36. -------------------
  37. .. _class_Semaphore_method_post:
  38. .. rst-class:: classref-method
  39. void **post** **(** **)**
  40. Lowers the **Semaphore**, allowing one more thread in.
  41. .. rst-class:: classref-item-separator
  42. ----
  43. .. _class_Semaphore_method_try_wait:
  44. .. rst-class:: classref-method
  45. :ref:`bool<class_bool>` **try_wait** **(** **)**
  46. Like :ref:`wait<class_Semaphore_method_wait>`, but won't block, so if the value is zero, fails immediately and returns ``false``. If non-zero, it returns ``true`` to report success.
  47. .. rst-class:: classref-item-separator
  48. ----
  49. .. _class_Semaphore_method_wait:
  50. .. rst-class:: classref-method
  51. void **wait** **(** **)**
  52. Waits for the **Semaphore**, if its value is zero, blocks until non-zero.
  53. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  54. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  55. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  56. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  57. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  58. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`