class_semaphore.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Semaphore.xml.
  6. .. _class_Semaphore:
  7. Semaphore
  8. =========
  9. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. A synchronization semaphore.
  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. \ **Warning:**\
  16. To guarantee that the operating system is able to perform proper cleanup (no crashes, no deadlocks), these conditions must be met:
  17. - By the time a **Semaphore**'s reference count reaches zero and therefore it is destroyed, no threads must be waiting on it.
  18. - By the time a :ref:`Thread<class_Thread>`'s reference count reaches zero and therefore it is destroyed, it must not be waiting on any semaphore.
  19. .. rst-class:: classref-introduction-group
  20. Tutorials
  21. ---------
  22. - :doc:`../tutorials/performance/threads/using_multiple_threads`
  23. .. rst-class:: classref-reftable-group
  24. Methods
  25. -------
  26. .. table::
  27. :widths: auto
  28. +---------------------------------------+--------------------------------------------------------------+
  29. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`post<class_Semaphore_method_post>` **(** **)** |
  30. +---------------------------------------+--------------------------------------------------------------+
  31. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`try_wait<class_Semaphore_method_try_wait>` **(** **)** |
  32. +---------------------------------------+--------------------------------------------------------------+
  33. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`wait<class_Semaphore_method_wait>` **(** **)** |
  34. +---------------------------------------+--------------------------------------------------------------+
  35. .. rst-class:: classref-section-separator
  36. ----
  37. .. rst-class:: classref-descriptions-group
  38. Method Descriptions
  39. -------------------
  40. .. _class_Semaphore_method_post:
  41. .. rst-class:: classref-method
  42. :ref:`Error<enum_@GlobalScope_Error>` **post** **(** **)**
  43. Lowers the **Semaphore**, allowing one more thread in.
  44. \ **Note:** This method internals' can't possibly fail, but an error code is returned for backwards compatibility, which will always be :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>`.
  45. .. rst-class:: classref-item-separator
  46. ----
  47. .. _class_Semaphore_method_try_wait:
  48. .. rst-class:: classref-method
  49. :ref:`Error<enum_@GlobalScope_Error>` **try_wait** **(** **)**
  50. Like :ref:`wait<class_Semaphore_method_wait>`, but won't block, so if the value is zero, fails immediately and returns :ref:`@GlobalScope.ERR_BUSY<class_@GlobalScope_constant_ERR_BUSY>`. If non-zero, it returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` to report success.
  51. .. rst-class:: classref-item-separator
  52. ----
  53. .. _class_Semaphore_method_wait:
  54. .. rst-class:: classref-method
  55. :ref:`Error<enum_@GlobalScope_Error>` **wait** **(** **)**
  56. Waits for the **Semaphore**, if its value is zero, blocks until non-zero.
  57. \ **Note:** This method internals' can't possibly fail, but an error code is returned for backwards compatibility, which will always be :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>`.
  58. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  59. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  60. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  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.)`