class_thread.rst 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Thread.xml.
  6. .. _class_Thread:
  7. Thread
  8. ======
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. A unit of execution in a process.
  11. Description
  12. -----------
  13. 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.
  14. \ **Note:** Breakpoints won't break on code if it's running in a thread. This is a current limitation of the GDScript debugger.
  15. Tutorials
  16. ---------
  17. - :doc:`Using multiple threads <../tutorials/performance/using_multiple_threads>`
  18. - :doc:`Thread-safe APIs <../tutorials/performance/thread_safe_apis>`
  19. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/676>`__
  20. Methods
  21. -------
  22. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`String<class_String>` | :ref:`get_id<class_Thread_method_get_id>` **(** **)** |const| |
  24. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`bool<class_bool>` | :ref:`is_alive<class_Thread_method_is_alive>` **(** **)** |const| |
  26. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`bool<class_bool>` | :ref:`is_started<class_Thread_method_is_started>` **(** **)** |const| |
  28. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`start<class_Thread_method_start>` **(** :ref:`Callable<class_Callable>` callable, :ref:`Priority<enum_Thread_Priority>` priority=1 **)** |
  30. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Variant<class_Variant>` | :ref:`wait_to_finish<class_Thread_method_wait_to_finish>` **(** **)** |
  32. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  33. Enumerations
  34. ------------
  35. .. _enum_Thread_Priority:
  36. .. _class_Thread_constant_PRIORITY_LOW:
  37. .. _class_Thread_constant_PRIORITY_NORMAL:
  38. .. _class_Thread_constant_PRIORITY_HIGH:
  39. enum **Priority**:
  40. - **PRIORITY_LOW** = **0** --- A thread running with lower priority than normally.
  41. - **PRIORITY_NORMAL** = **1** --- A thread with a standard priority.
  42. - **PRIORITY_HIGH** = **2** --- A thread running with higher priority than normally.
  43. Method Descriptions
  44. -------------------
  45. .. _class_Thread_method_get_id:
  46. - :ref:`String<class_String>` **get_id** **(** **)** |const|
  47. Returns the current ``Thread``'s ID, uniquely identifying it among all threads. If the ``Thread`` is not running this returns an empty string.
  48. ----
  49. .. _class_Thread_method_is_alive:
  50. - :ref:`bool<class_bool>` **is_alive** **(** **)** |const|
  51. Returns ``true`` if this ``Thread`` is currently running. This is useful for determining if :ref:`wait_to_finish<class_Thread_method_wait_to_finish>` can be called without blocking the calling thread.
  52. To check if a ``Thread`` is joinable, use :ref:`is_started<class_Thread_method_is_started>`.
  53. ----
  54. .. _class_Thread_method_is_started:
  55. - :ref:`bool<class_bool>` **is_started** **(** **)** |const|
  56. Returns ``true`` if this ``Thread`` has been started. Once started, this will return ``true`` until it is joined using :ref:`wait_to_finish<class_Thread_method_wait_to_finish>`. For checking if a ``Thread`` is still executing its task, use :ref:`is_alive<class_Thread_method_is_alive>`.
  57. ----
  58. .. _class_Thread_method_start:
  59. - :ref:`Error<enum_@GlobalScope_Error>` **start** **(** :ref:`Callable<class_Callable>` callable, :ref:`Priority<enum_Thread_Priority>` priority=1 **)**
  60. Starts a new ``Thread`` that calls ``callable``.
  61. If the method takes some arguments, you can pass them using :ref:`Callable.bind<class_Callable_method_bind>`.
  62. The ``priority`` of the ``Thread`` can be changed by passing a value from the :ref:`Priority<enum_Thread_Priority>` enum.
  63. Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success, or :ref:`@GlobalScope.ERR_CANT_CREATE<class_@GlobalScope_constant_ERR_CANT_CREATE>` on failure.
  64. ----
  65. .. _class_Thread_method_wait_to_finish:
  66. - :ref:`Variant<class_Variant>` **wait_to_finish** **(** **)**
  67. Joins the ``Thread`` and waits for it to finish. Returns the output of the :ref:`Callable<class_Callable>` passed to :ref:`start<class_Thread_method_start>`.
  68. 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``.
  69. To determine if this can be called without blocking the calling thread, check if :ref:`is_alive<class_Thread_method_is_alive>` is ``false``.
  70. \ **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.
  71. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  72. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  73. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  74. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  75. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  76. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`