Files
godot-docs/classes/class_thread.rst

93 lines
4.9 KiB
ReStructuredText

:github_url: hide
.. Generated automatically by doc/tools/makerst.py in Godot's source tree.
.. DO NOT EDIT THIS FILE, but the Thread.xml source instead.
.. The source is found in doc/classes or modules/<name>/doc_classes.
.. _class_Thread:
Thread
======
**Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
A unit of execution in a process.
Description
-----------
A unit of execution in a process. Can run methods on :ref:`Object<class_Object>`\ s simultaneously. The use of synchronization via :ref:`Mutex<class_Mutex>` or :ref:`Semaphore<class_Semaphore>` is advised if working with shared objects.
Tutorials
---------
- :doc:`../tutorials/performance/using_multiple_threads`
Methods
-------
+---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`String<class_String>` | :ref:`get_id<class_Thread_method_get_id>` **(** **)** const |
+---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`is_active<class_Thread_method_is_active>` **(** **)** const |
+---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`start<class_Thread_method_start>` **(** :ref:`Object<class_Object>` instance, :ref:`StringName<class_StringName>` method, :ref:`Variant<class_Variant>` userdata=null, :ref:`Priority<enum_Thread_Priority>` priority=1 **)** |
+---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Variant<class_Variant>` | :ref:`wait_to_finish<class_Thread_method_wait_to_finish>` **(** **)** |
+---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Enumerations
------------
.. _enum_Thread_Priority:
.. _class_Thread_constant_PRIORITY_LOW:
.. _class_Thread_constant_PRIORITY_NORMAL:
.. _class_Thread_constant_PRIORITY_HIGH:
enum **Priority**:
- **PRIORITY_LOW** = **0** --- A thread running with lower priority than normally.
- **PRIORITY_NORMAL** = **1** --- A thread with a standard priority.
- **PRIORITY_HIGH** = **2** --- A thread running with higher priority than normally.
Method Descriptions
-------------------
.. _class_Thread_method_get_id:
- :ref:`String<class_String>` **get_id** **(** **)** const
Returns the current ``Thread``'s ID, uniquely identifying it among all threads.
----
.. _class_Thread_method_is_active:
- :ref:`bool<class_bool>` **is_active** **(** **)** const
Returns ``true`` if this ``Thread`` is currently active. An active ``Thread`` cannot start work on a new method but can be joined with :ref:`wait_to_finish<class_Thread_method_wait_to_finish>`.
----
.. _class_Thread_method_start:
- :ref:`Error<enum_@GlobalScope_Error>` **start** **(** :ref:`Object<class_Object>` instance, :ref:`StringName<class_StringName>` method, :ref:`Variant<class_Variant>` userdata=null, :ref:`Priority<enum_Thread_Priority>` priority=1 **)**
Starts a new ``Thread`` that runs ``method`` on object ``instance`` with ``userdata`` passed as an argument. The ``priority`` of the ``Thread`` can be changed by passing a value from the :ref:`Priority<enum_Thread_Priority>` enum.
Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success, or :ref:`@GlobalScope.ERR_CANT_CREATE<class_@GlobalScope_constant_ERR_CANT_CREATE>` on failure.
----
.. _class_Thread_method_wait_to_finish:
- :ref:`Variant<class_Variant>` **wait_to_finish** **(** **)**
Joins the ``Thread`` and waits for it to finish. Returns what the method called returned.