Threads functions for using GDK in multi-threaded programs 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. 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. This macro marks the end of a critical section begun with #GDK_THREADS_ENTER. Enters a critical region like #GDK_THREADS_ENTER. Leaves a critical region begun with gdk_threads_enter(). The #GMutex used to implement the critical region for gdk_threads_enter()/gdk_threads_leave().