From the source definition it looks like you can attach a GSource only to one GMainContext
struct _GSource
{
/*< private >*/
gpointer callback_data;
GSourceCallbackFuncs *callback_funcs;
const GSourceFuncs *source_funcs;
guint ref_count;
GMainContext *context; // <<<<<
gint priority;
guint flags;
guint source_id;
GSList *poll_fds;
GSource *prev;
GSource *next;
char *name;
GSourcePrivate *priv;
};
Have a look at
static guint
g_source_attach_unlocked (GSource *source,
GMainContext *context,
gboolean do_wakeup)
which will tell you that only the associated GMainContext
will be woken.
Example of derived GSource
usage: https://github.com/chergert/iris/blob/master/iris/iris-gsource.c