GDK Reference Manual | |||
---|---|---|---|
<<< Previous Page | Home | Up | Next Page >>> |
#include <gdk/gdk.h> #define GDK_THREADS_ENTER () #define GDK_THREADS_LEAVE () void gdk_threads_init (void); void gdk_threads_enter (void); void gdk_threads_leave (void); extern GMutex *gdk_threads_mutex; |
For thread safety, GDK relies on the thread primitives in GLib, and on the thread-safe GLib main loop.
You must call g_thread_init() before executing any other GTK+ or GDK functions in a threaded GTK+ program.
Idles, timeouts, and input functions are executed outside of the main GTK+ lock. So, if you need to call GTK+ inside of such a callback, you must surround the callback with a gdk_threads_enter()/gdk_threads_leave() pair. (However, signals are still executed within the main GTK+ lock.)
In particular, this means, if you are writing widgets that might be used in threaded programs, you must surround timeouts and idle functions in this matter.
As always, you must also surround any calls to GTK+ not made within a signal handler with a gdk_threads_enter()/gdk_threads_leave() pair.
#define GDK_THREADS_ENTER() |
This macro marks the begin of a critical section in which GDK and GTK+ functions can be called. Only one thread at a time can be in such a critial section.
#define GDK_THREADS_LEAVE() |
This macro marks the end of a critical section begun with GDK_THREADS_ENTER.
void gdk_threads_init (void); |
Initializes GDK so that it can be used from multiple threads in conjunction with gdk_threads_enter() and gdk_threads_leave(). g_thread_init() must be called previous to this function.
This call must be made before any use of the main loop from GTK+; to be safe, call it before gtk_init().
void gdk_threads_leave (void); |
Leaves a critical region begun with gdk_threads_enter().
extern GMutex *gdk_threads_mutex; |
The GMutex used to implement the critical region for gdk_threads_enter()/gdk_threads_leave().