~ubuntu-branches/ubuntu/trusty/glibmm2.4/trusty

« back to all changes in this revision

Viewing changes to glib/glibmm/threads.h

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2012-03-08 11:46:37 UTC
  • mfrom: (1.2.70)
  • Revision ID: package-import@ubuntu.com-20120308114637-igm0brktjj83b03b
Tags: 2.31.20-0ubuntu1
New upstream version

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#ifndef _GLIBMM_THREADS_H
4
4
#define _GLIBMM_THREADS_H
5
5
 
 
6
#include <glibmmconfig.h>
 
7
 
6
8
 
7
9
/* Copyright (C) 2002 The gtkmm Development Team
8
10
 *
22
24
 */
23
25
 
24
26
 
25
 
#include <glibmmconfig.h>
26
 
 
27
27
#include <glib.h>
28
28
 
29
29
#include <glibmm/error.h>
36
36
 
37
37
namespace Threads
38
38
{
 
39
//The GMMPROC_EXTRA_NAMESPACE() macro is a hint to generate_wrap_init.pl to put it in the Threads sub-namespace
 
40
 
39
41
 
40
42
/** @defgroup Threads Threads
41
43
 * Thread abstraction; including threads, different mutexes,
77
79
 
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.
84
84
 *
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
89
89
 * entry function.
90
90
 *
91
91
 * @note You might have noticed that the thread entry slot doesn't have the
98
98
  class Exit;
99
99
 
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().
104
103
   *
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.
108
107
   *
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.
112
111
   *
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
117
115
   */
118
 
  static Thread* create(const sigc::slot<void>& slot, bool joinable = true);
 
116
  static Thread* create(const sigc::slot<void>& slot);
119
117
 
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&nbsp;=&nbsp;true</tt>.
 
127
   * the thread including the Glib::Threads::Thread object are released.
131
128
   */
132
129
  void join();
133
130
 
155
152
 
156
153
/** %Exception class used to exit from a thread.
157
154
 * @code
158
 
 * throw Glib::Thread::Exit();
 
155
 * throw Glib::Threads::Thread::Exit();
159
156
 * @endcode
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.
163
160
 */
164
161
class Thread::Exit
165
162
{};
166
163
 
167
 
/** @relates Glib::Thread */
 
164
/** @relates Glib::Threads::Thread */
168
165
Thread* wrap(GThread* gobject);
169
166
 
170
167
/** Represents a mutex (mutual exclusion).