:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Semaphore.xml. .. _class_Semaphore: Semaphore ========= **Inherits:** :ref:`Reference` **<** :ref:`Object` A synchronization semaphore. .. rst-class:: classref-introduction-group Description ----------- A synchronization semaphore which can be used to synchronize multiple :ref:`Thread`\ s. Initialized to zero on creation. Be careful to avoid deadlocks. For a binary version, see :ref:`Mutex`. \ **Warning:**\ To guarantee that the operating system is able to perform proper cleanup (no crashes, no deadlocks), these conditions must be met: - By the time a **Semaphore**'s reference count reaches zero and therefore it is destroyed, no threads must be waiting on it. - By the time a :ref:`Thread`'s reference count reaches zero and therefore it is destroyed, it must not be waiting on any semaphore. .. rst-class:: classref-introduction-group Tutorials --------- - :doc:`../tutorials/performance/threads/using_multiple_threads` .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +---------------------------------------+--------------------------------------------------------------+ | :ref:`Error` | :ref:`post` **(** **)** | +---------------------------------------+--------------------------------------------------------------+ | :ref:`Error` | :ref:`try_wait` **(** **)** | +---------------------------------------+--------------------------------------------------------------+ | :ref:`Error` | :ref:`wait` **(** **)** | +---------------------------------------+--------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_Semaphore_method_post: .. rst-class:: classref-method :ref:`Error` **post** **(** **)** Lowers the **Semaphore**, allowing one more thread in. \ **Note:** This method internals' can't possibly fail, but an error code is returned for backwards compatibility, which will always be :ref:`@GlobalScope.OK`. .. rst-class:: classref-item-separator ---- .. _class_Semaphore_method_try_wait: .. rst-class:: classref-method :ref:`Error` **try_wait** **(** **)** Like :ref:`wait`, but won't block, so if the value is zero, fails immediately and returns :ref:`@GlobalScope.ERR_BUSY`. If non-zero, it returns :ref:`@GlobalScope.OK` to report success. .. rst-class:: classref-item-separator ---- .. _class_Semaphore_method_wait: .. rst-class:: classref-method :ref:`Error` **wait** **(** **)** Waits for the **Semaphore**, if its value is zero, blocks until non-zero. \ **Note:** This method internals' can't possibly fail, but an error code is returned for backwards compatibility, which will always be :ref:`@GlobalScope.OK`. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`