Re: Handling Unix signals in a GTK+ application
- From: Tristan Van Berkom <tristan van berkom gmail com>
- To: "David Necas (Yeti)" <yeti physics muni cz>
- Cc: gtk-app-devel-list gnome org, fredderic excite com
- Subject: Re: Handling Unix signals in a GTK+ application
- Date: Thu, 16 Mar 2006 17:46:05 -0500
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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]