class_semaphore.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/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 that can be used to synchronize multiple :ref:`Thread<class_Thread>`\ s. Initialized to zero on creation. For a binary version, see :ref:`Mutex<class_Mutex>`.
  15. \ **Warning:** Semaphores must be used carefully to avoid deadlocks.
  16. \ **Warning:** To guarantee that the operating system is able to perform proper cleanup (no crashes, no deadlocks), these conditions must be met:
  17. - When a **Semaphore**'s reference count reaches zero and it is therefore destroyed, no threads must be waiting on it.
  18. - When a :ref:`Thread<class_Thread>`'s reference count reaches zero and it is therefore destroyed, it must not be waiting on any semaphore.
  19. .. rst-class:: classref-introduction-group
  20. Tutorials
  21. ---------
  22. - :doc:`Using multiple threads <../tutorials/performance/using_multiple_threads>`
  23. - :doc:`Thread-safe APIs <../tutorials/performance/thread_safe_apis>`
  24. .. rst-class:: classref-reftable-group
  25. Methods
  26. -------
  27. .. table::
  28. :widths: auto
  29. +-------------------------+-----------------------------------------------------------------------------------+
  30. | |void| | :ref:`post<class_Semaphore_method_post>`\ (\ count\: :ref:`int<class_int>` = 1\ ) |
  31. +-------------------------+-----------------------------------------------------------------------------------+
  32. | :ref:`bool<class_bool>` | :ref:`try_wait<class_Semaphore_method_try_wait>`\ (\ ) |
  33. +-------------------------+-----------------------------------------------------------------------------------+
  34. | |void| | :ref:`wait<class_Semaphore_method_wait>`\ (\ ) |
  35. +-------------------------+-----------------------------------------------------------------------------------+
  36. .. rst-class:: classref-section-separator
  37. ----
  38. .. rst-class:: classref-descriptions-group
  39. Method Descriptions
  40. -------------------
  41. .. _class_Semaphore_method_post:
  42. .. rst-class:: classref-method
  43. |void| **post**\ (\ count\: :ref:`int<class_int>` = 1\ ) :ref:`🔗<class_Semaphore_method_post>`
  44. Lowers the **Semaphore**, allowing one thread in, or more if ``count`` is specified.
  45. .. rst-class:: classref-item-separator
  46. ----
  47. .. _class_Semaphore_method_try_wait:
  48. .. rst-class:: classref-method
  49. :ref:`bool<class_bool>` **try_wait**\ (\ ) :ref:`🔗<class_Semaphore_method_try_wait>`
  50. 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.
  51. .. rst-class:: classref-item-separator
  52. ----
  53. .. _class_Semaphore_method_wait:
  54. .. rst-class:: classref-method
  55. |void| **wait**\ (\ ) :ref:`🔗<class_Semaphore_method_wait>`
  56. Waits for the **Semaphore**, if its value is zero, blocks until non-zero.
  57. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  58. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  59. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  60. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  61. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  62. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  63. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  64. .. |void| replace:: :abbr:`void (No return value.)`