123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- :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<class_Reference>` **<** :ref:`Object<class_Object>`
- A synchronization semaphore.
- .. rst-class:: classref-introduction-group
- Description
- -----------
- 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>`.
- \ **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<class_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<enum_@GlobalScope_Error>` | :ref:`post<class_Semaphore_method_post>` **(** **)** |
- +---------------------------------------+--------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`try_wait<class_Semaphore_method_try_wait>` **(** **)** |
- +---------------------------------------+--------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`wait<class_Semaphore_method_wait>` **(** **)** |
- +---------------------------------------+--------------------------------------------------------------+
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Method Descriptions
- -------------------
- .. _class_Semaphore_method_post:
- .. rst-class:: classref-method
- :ref:`Error<enum_@GlobalScope_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<class_@GlobalScope_constant_OK>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Semaphore_method_try_wait:
- .. rst-class:: classref-method
- :ref:`Error<enum_@GlobalScope_Error>` **try_wait** **(** **)**
- 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.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Semaphore_method_wait:
- .. rst-class:: classref-method
- :ref:`Error<enum_@GlobalScope_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<class_@GlobalScope_constant_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.)`
|