David Necas (Yeti) wrote:
On Thu, Mar 16, 2006 at 03:55:50PM -0500, Tristan Van Berkom wrote:
Well, it locks a mutex before accessing the GMainContext; so if gtk+ is
compiled with threads... it should work... unless I'm on crack and mutexes
are useless from signal handlers... but I dont think so.
Maybe I'm missing something, but how does this help when the
signal is delivered to the thread which is just inside
g_idle_add() (the only thread in a single-threaded program)?
You are absolutely right; mutexes /are/ useless from signal handlers,
cooking the inline crack included below with gcc will prove it ;-)
It seems the only reasonable way is to use a pipe().
Cheers,
-Tristan
=======================================
#include <glib.h>
#include <signal.h>
GMutex *common_mutex;
void my_sigint (gint signum);
void
my_sigint (gint signum)
{
signal (SIGINT, my_sigint);
g_print ("Before lock\n");
g_mutex_lock (common_mutex);
g_print ("After lock\n");
}
gboolean
my_timeout (gpointer data)
{
g_print ("Called\n");
return TRUE;
}
void main()
{
GMainLoop *loop;
g_thread_init (NULL);
if (!g_thread_supported ())
g_error ("No thread support");
signal (SIGINT, my_sigint);
g_timeout_add (1000, my_timeout, NULL);
loop = g_main_loop_new (NULL, FALSE);
common_mutex = g_mutex_new ();
g_mutex_lock (common_mutex);
g_main_loop_run (loop);
}
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list