78
80
/** Represents a running thread.
79
81
* An instance of this class can only be obtained with create(), self(),
80
* or wrap(GThread*). It's not possible to delete a Thread object. If the
81
* thread is @em not joinable, its resources will be freed automatically
82
* when it exits. Otherwise, if the thread @em is joinable, you must call
83
* join() to avoid a memory leak.
82
* or wrap(GThread*). It's not possible to delete a Thread object.
83
* You must call join() to avoid a memory leak.
85
85
* @note g_thread_exit() is not wrapped, because that function exits a thread
86
86
* without any cleanup. That's especially dangerous in C++ code, since the
87
87
* destructors of automatic objects won't be invoked. Instead, you can throw
88
* a Thread::Exit exception, which will be caught by the internal thread
88
* a Threads::Thread::Exit exception, which will be caught by the internal thread
91
91
* @note You might have noticed that the thread entry slot doesn't have the
100
100
//See http://bugzilla.gnome.org/show_bug.cgi?id=512348 about the sigc::trackable issue.
101
/** Creates a new thread with the priority <tt>THREAD_PRIORITY_NORMAL</tt>.
102
* If @a joinable is @c true, you can wait for this thread's termination by
103
* calling join(). Otherwise the thread will just disappear, when ready.
101
/** Creates a new thread.
102
* You can wait for this thread's termination by calling join().
105
104
* The new thread executes the function or method @a slot points to. You can
106
105
* pass additional arguments using sigc::bind(). If the thread was created
107
* successfully, it is returned, otherwise a ThreadError exception is thrown.
106
* successfully, it is returned, otherwise a Threads::ThreadError exception is thrown.
109
108
* Because sigc::trackable is not thread safe, if the slot represents a
110
109
* non-static class method (that is, it is created by sigc::mem_fun()), the
111
110
* class concerned should not derive from sigc::trackable.
113
112
* @param slot A slot to execute in the new thread.
114
* @param joinable This parameter is now ignored because Threads are now always joinable.
115
113
* @return The new Thread* on success.
116
* @throw Glib::ThreadError
114
* @throw Glib::Threads::ThreadError
118
static Thread* create(const sigc::slot<void>& slot, bool joinable = true);
116
static Thread* create(const sigc::slot<void>& slot);
120
118
/** Returns the Thread* corresponding to the calling thread.
121
119
* @return The current thread.
126
124
* Waits until the thread finishes, i.e. the slot, as given to create(),
127
125
* returns or g_thread_exit() is called by the thread. (Calling
128
126
* g_thread_exit() in a C++ program should be avoided.) All resources of
129
* the thread including the Glib::Thread object are released. The thread
130
* must have been created with <tt>joinable = true</tt>.
127
* the thread including the Glib::Threads::Thread object are released.
156
153
/** %Exception class used to exit from a thread.
158
* throw Glib::Thread::Exit();
155
* throw Glib::Threads::Thread::Exit();
160
* Write this if you want to exit from a thread created by Thread::create().
161
* Of course you must make sure not to catch Thread::Exit by accident, i.e.
157
* Write this if you want to exit from a thread created by Threads::Thread::create().
158
* Of course you must make sure not to catch Threads::Thread::Exit by accident, i.e.
162
159
* when using <tt>catch(...)</tt> somewhere in your code.
164
161
class Thread::Exit
167
/** @relates Glib::Thread */
164
/** @relates Glib::Threads::Thread */
168
165
Thread* wrap(GThread* gobject);
170
167
/** Represents a mutex (mutual exclusion).