.. index:: pair: class; EE::System::Thread .. _doxid-class_e_e_1_1_system_1_1_thread: class EE::System::Thread ======================== .. toctree:: :hidden: Overview ~~~~~~~~ :ref:`Thread ` manager class. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class Thread: private :ref:`EE::NonCopyable` { public: // typedefs typedef void (*:target:`FuncType`)(void *); // construction template :ref:`Thread`(F function); template :ref:`Thread`(F function, A argument); template :ref:`Thread`(void(C::*)() function, C* object); virtual :ref:`~Thread`(); // methods static :ref:`Uint32` :ref:`getCurrentThreadId`(); void :ref:`launch`(); void :ref:`wait`(); void :ref:`terminate`(); :ref:`Uint32` :ref:`getId`(); }; .. _details-class_e_e_1_1_system_1_1_thread: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ :ref:`Thread ` manager class. Construction ------------ .. index:: pair: function; Thread .. _doxid-class_e_e_1_1_system_1_1_thread_1abcef3406cba740e569735dc5e31d7bb8: .. ref-code-block:: cpp :class: doxyrest-title-code-block template Thread(F function) Construct the thread from a functor with no argument This constructor works for function objects, as well as free function. Use this constructor for this kind of function: .. ref-code-block:: cpp void function(); --- or ---- struct Functor { void operator()(); }; Note: this does *not* run the thread, use Launch(). .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - function - Functor or free function to use as the entry point of the thread .. index:: pair: function; Thread .. _doxid-class_e_e_1_1_system_1_1_thread_1a1b437ec3eca5092a8070f5693a1d5ab6: .. ref-code-block:: cpp :class: doxyrest-title-code-block template Thread(F function, A argument) Construct the thread from a functor with an argument This constructor works for function objects, as well as free function. It is a template, which means that the argument can have any type (int, std::string, void\*, Toto, ...). Use this constructor for this kind of function: .. ref-code-block:: cpp void function(int arg); --- or ---- struct Functor { void operator()(std::string arg); }; Note: this does *not* run the thread, use Launch(). .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - function - Functor or free function to use as the entry point of the thread * - argument - argument to forward to the function .. index:: pair: function; Thread .. _doxid-class_e_e_1_1_system_1_1_thread_1a110219a97a8d81a0e50cba1b31b6d336: .. ref-code-block:: cpp :class: doxyrest-title-code-block template Thread(void(C::*)() function, C* object) Construct the thread from a member function and an object This constructor is template, which means that you can use it with any class. Use this constructor for this kind of function: .. ref-code-block:: cpp class MyClass { public : void function(); }; Note: this does *not* run the thread, use Launch(). .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - function - Entry point of the thread * - object - Pointer to the object to use .. _doxid-class_e_e_1_1_system_1_1_thread_1ab171c7603a3b3a9e1ad7461cc9dbb07f: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual ~Thread() Destructor This destructor calls Wait(), so that the internal thread cannot survive after its :ref:`Thread ` instance is destroyed. Methods ------- .. index:: pair: function; getCurrentThreadId .. _doxid-class_e_e_1_1_system_1_1_thread_1a3d332a791dc6ca7ef537991274917b60: .. ref-code-block:: cpp :class: doxyrest-title-code-block static :ref:`Uint32` getCurrentThreadId() .. rubric:: Returns: The current thread id .. index:: pair: function; launch .. _doxid-class_e_e_1_1_system_1_1_thread_1aaf5136c7e89209c1fa0d27f1ed86b3d0: .. ref-code-block:: cpp :class: doxyrest-title-code-block void launch() Run the thread This function starts the entry point passed to the thread's constructor, and returns immediately. After this function returns, the thread's function is running in parallel to the calling code. .. index:: pair: function; wait .. _doxid-class_e_e_1_1_system_1_1_thread_1a480013b118495e239305f123dd8e776a: .. ref-code-block:: cpp :class: doxyrest-title-code-block void wait() Wait until the thread finishes. This function will block the execution until the thread's function ends. Warning: if the thread function never ends, the calling thread will block forever. If this function is called from its owner thread, it returns without doing anything. .. index:: pair: function; terminate .. _doxid-class_e_e_1_1_system_1_1_thread_1a3ee84ae9432eab613e4d871635281719: .. ref-code-block:: cpp :class: doxyrest-title-code-block void terminate() Terminate the thread This function immediately stops the thread, without waiting for its function to finish. Terminating a thread with this function is not safe, and can lead to local variables not being destroyed on some operating systems. You should rather try to make the thread function terminate by itself. .. index:: pair: function; getId .. _doxid-class_e_e_1_1_system_1_1_thread_1a02eb997569de5e1467bed592fc1f9ddb: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Uint32` getId() .. rubric:: Returns: The id of the thread