I'm working with both libfuse and the glib event interface and I've run into an issue where I need to run multiple main loops concurrently (glib's g_main_loop_run
and fuse_loop_mt
).
I've already attempted to created a detached thread for glib's event loop under a secondary context, e.g.:
static void *
event_loop(void *arg)
{
GMainLoop *event_loop;
GMainContext *context;
context = g_main_context_new();
g_main_context_push_thread_default(context);
event_loop = g_main_loop_new(context, FALSE);
g_main_loop_run(event_loop);
return NULL;
}
...
pthread_t event_thread;
pthread_attr_t thread_attr;
pthread_attr_init(&thread_attr);
pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
event_thread = pthread_create(&event_thread, &thread_attr,
event_loop, NULL);
However the glib event loop doesn't pick up on any of the fired events. Am I totally off-base here? What's the proper way to tackle multiple main loops?