class_thread.rst 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Thread.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Thread:
  6. Thread
  7. ======
  8. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. A unit of execution in a process.
  10. Description
  11. -----------
  12. 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.
  13. Tutorials
  14. ---------
  15. - :doc:`../tutorials/threads/using_multiple_threads`
  16. - :doc:`../tutorials/threads/thread_safe_apis`
  17. Methods
  18. -------
  19. +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`String<class_String>` | :ref:`get_id<class_Thread_method_get_id>` **(** **)** const |
  21. +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`bool<class_bool>` | :ref:`is_active<class_Thread_method_is_active>` **(** **)** const |
  23. +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`start<class_Thread_method_start>` **(** :ref:`Object<class_Object>` instance, :ref:`String<class_String>` method, :ref:`Variant<class_Variant>` userdata=null, :ref:`Priority<enum_Thread_Priority>` priority=1 **)** |
  25. +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Variant<class_Variant>` | :ref:`wait_to_finish<class_Thread_method_wait_to_finish>` **(** **)** |
  27. +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. Enumerations
  29. ------------
  30. .. _enum_Thread_Priority:
  31. .. _class_Thread_constant_PRIORITY_LOW:
  32. .. _class_Thread_constant_PRIORITY_NORMAL:
  33. .. _class_Thread_constant_PRIORITY_HIGH:
  34. enum **Priority**:
  35. - **PRIORITY_LOW** = **0** --- A thread running with lower priority than normally.
  36. - **PRIORITY_NORMAL** = **1** --- A thread with a standard priority.
  37. - **PRIORITY_HIGH** = **2** --- A thread running with higher priority than normally.
  38. Method Descriptions
  39. -------------------
  40. .. _class_Thread_method_get_id:
  41. - :ref:`String<class_String>` **get_id** **(** **)** const
  42. Returns the current ``Thread``'s ID, uniquely identifying it among all threads.
  43. ----
  44. .. _class_Thread_method_is_active:
  45. - :ref:`bool<class_bool>` **is_active** **(** **)** const
  46. 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>`.
  47. ----
  48. .. _class_Thread_method_start:
  49. - :ref:`Error<enum_@GlobalScope_Error>` **start** **(** :ref:`Object<class_Object>` instance, :ref:`String<class_String>` method, :ref:`Variant<class_Variant>` userdata=null, :ref:`Priority<enum_Thread_Priority>` priority=1 **)**
  50. 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_Thread_Priority>` enum.
  51. Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success, or :ref:`@GlobalScope.ERR_CANT_CREATE<class_@GlobalScope_constant_ERR_CANT_CREATE>` on failure.
  52. ----
  53. .. _class_Thread_method_wait_to_finish:
  54. - :ref:`Variant<class_Variant>` **wait_to_finish** **(** **)**
  55. Joins the ``Thread`` and waits for it to finish. Returns what the method called returned.