:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/3.5/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/3.5/doc/classes/Thread.xml. .. _class_Thread: Thread ====== **Inherits:** :ref:`Reference` **<** :ref:`Object` A unit of execution in a process. Description ----------- A unit of execution in a process. Can run methods on :ref:`Object`\ s simultaneously. The use of synchronization via :ref:`Mutex` or :ref:`Semaphore` is advised if working with shared objects. \ **Note:** Breakpoints won't break on code if it's running in a thread. This is a current limitation of the GDScript debugger. Tutorials --------- - :doc:`Using multiple threads <../tutorials/performance/threads/using_multiple_threads>` - :doc:`Thread-safe APIs <../tutorials/performance/threads/thread_safe_apis>` - `3D Voxel Demo `__ Methods ------- +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`get_id` **(** **)** |const| | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_active` **(** **)** |const| | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_alive` **(** **)** |const| | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`start` **(** :ref:`Object` instance, :ref:`String` method, :ref:`Variant` userdata=null, :ref:`Priority` priority=1 **)** | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`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` **get_id** **(** **)** |const| Returns the current ``Thread``'s ID, uniquely identifying it among all threads. If the ``Thread`` is not running this returns an empty string. ---- .. _class_Thread_method_is_active: - :ref:`bool` **is_active** **(** **)** |const| Returns ``true`` if this ``Thread`` has been started. Once started, this will return ``true`` until it is joined using :ref:`wait_to_finish`. For checking if a ``Thread`` is still executing its task, use :ref:`is_alive`. ---- .. _class_Thread_method_is_alive: - :ref:`bool` **is_alive** **(** **)** |const| Returns ``true`` if this ``Thread`` is currently running. This is useful for determining if :ref:`wait_to_finish` can be called without blocking the calling thread. To check if a ``Thread`` is joinable, use :ref:`is_active`. ---- .. _class_Thread_method_start: - :ref:`Error` **start** **(** :ref:`Object` instance, :ref:`String` method, :ref:`Variant` userdata=null, :ref:`Priority` priority=1 **)** Starts a new ``Thread`` that runs ``method`` on object ``instance`` with ``userdata`` passed as an argument. Even if no userdata is passed, ``method`` must accept one argument and it will be null. The ``priority`` of the ``Thread`` can be changed by passing a value from the :ref:`Priority` enum. Returns :ref:`@GlobalScope.OK` on success, or :ref:`@GlobalScope.ERR_CANT_CREATE` on failure. ---- .. _class_Thread_method_wait_to_finish: - :ref:`Variant` **wait_to_finish** **(** **)** Joins the ``Thread`` and waits for it to finish. Returns the output of the method passed to :ref:`start`. Should either be used when you want to retrieve the value returned from the method called by the ``Thread`` or before freeing the instance that contains the ``Thread``. To determine if this can be called without blocking the calling thread, check if :ref:`is_alive` is ``false``. \ **Note:** After the ``Thread`` finishes joining it will be disposed. If you want to use it again you will have to create a new instance of it. .. |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.)`