+#ifdef G_THREADS_ENABLED
+static void
+g_main_context_init_pipe (GMainContext *context)
+{
+# ifndef G_OS_WIN32
+ if (pipe (context->wake_up_pipe) < 0)
+ g_error ("Cannot create pipe main loop wake-up: %s\n",
+ g_strerror (errno));
+
+ context->wake_up_rec.fd = context->wake_up_pipe[0];
+ context->wake_up_rec.events = G_IO_IN;
+# else
+ context->wake_up_semaphore = CreateSemaphore (NULL, 0, 100, NULL);
+ if (context->wake_up_semaphore == NULL)
+ g_error ("Cannot create wake-up semaphore: %s",
+ g_win32_error_message (GetLastError ()));
+ context->wake_up_rec.fd = (gint) context->wake_up_semaphore;
+ context->wake_up_rec.events = G_IO_IN;
+# ifdef G_MAIN_POLL_DEBUG
+ g_print ("wake-up semaphore: %#x\n", (guint) context->wake_up_semaphore);
+# endif
+# endif
+ g_main_context_add_poll_unlocked (context, 0, &context->wake_up_rec);
+}
+
+void
+g_main_thread_init ()
+{
+ GSList *curr = main_contexts_without_pipe;
+ while (curr)
+ {
+ g_main_context_init_pipe ((GMainContext *)curr->data);
+ curr = curr->next;
+ }
+ g_slist_free (main_contexts_without_pipe);
+ main_contexts_without_pipe = NULL;
+}
+#endif /* G_THREADS_ENABLED */
+