glibmm
2.33.3
|
Represents a running thread. More...
#include <glibmm/threads.h>
Classes | |
class | Exit |
Exception class used to exit from a thread. More... | |
Public Member Functions | |
void | join () |
Waits until the thread finishes. | |
GThread* | gobj () |
const GThread* | gobj () const |
Static Public Member Functions | |
static Thread* | create (const sigc::slot< void >& slot) |
Creates a new thread. | |
static Thread* | self () |
Returns the Thread* corresponding to the calling thread. | |
static void | yield () |
Gives way to other threads waiting to be scheduled. | |
Related Functions | |
(Note that these are not member functions.) | |
Thread* | wrap (GThread* gobject) |
Represents a running thread.
An instance of this class can only be obtained with create(), self(), or wrap(GThread*). It's not possible to delete a Thread object. You must call join() to avoid a memory leak.
static Thread* Glib::Threads::Thread::create | ( | const sigc::slot< void > & | slot | ) | [static] |
Creates a new thread.
You can wait for this thread's termination by calling join().
The new thread executes the function or method slot points to. You can pass additional arguments using sigc::bind(). If the thread was created successfully, it is returned, otherwise a Threads::ThreadError exception is thrown.
Because sigc::trackable is not thread safe, if the slot represents a non-static class method (that is, it is created by sigc::mem_fun()), the class concerned should not derive from sigc::trackable.
slot | A slot to execute in the new thread. |
Glib::Threads::ThreadError |
GThread* Glib::Threads::Thread::gobj | ( | ) | [inline] |
const GThread* Glib::Threads::Thread::gobj | ( | ) | const [inline] |
void Glib::Threads::Thread::join | ( | ) |
Waits until the thread finishes.
Waits until the thread finishes, i.e. the slot, as given to create(), returns or g_thread_exit() is called by the thread. (Calling g_thread_exit() in a C++ program should be avoided.) All resources of the thread including the Glib::Threads::Thread object are released.
static Thread* Glib::Threads::Thread::self | ( | ) | [static] |
Returns the Thread* corresponding to the calling thread.
static void Glib::Threads::Thread::yield | ( | ) | [static] |
Gives way to other threads waiting to be scheduled.
This function is often used as a method to make busy wait less evil. But in most cases, you will encounter, there are better methods to do that. So in general you shouldn't use this function.