g_timeout_add 의 경우 g_source_remove 쪽에 문제가 있는 것으로 보인다.
remove - add 반복시 아래 방식이 더 안정적이다. g context 문제가 생길 시에도 바로 확인이 가능하다.
{ GMainContext *context; GMainLoop *main_loop; GSource *source; /* Initialize thread support */ g_thread_init(NULL); /* Create a GLib Main Context */ context = g_main_context_new(); /* Create a Main Loop in the context*/ main_loop = g_main_loop_new(context, FALSE); /* Create new timeout source to be called * every 5 seconds. * Reference count of source is 1 once created */ source = g_timeout_source_new(TIMEOUT_MSECS); /* Set callback to be called in each timeout */ g_source_set_callback(source, (GSourceFunc)__timeout_func, main_loop, NULL); /* Attach the GSource in the GMainContext. * Reference count of source is 2 after this call */ g_source_attach(source, context); /* Run the main loop, until it is stopped */ g_main_loop_run(main_loop); /* We did an attach() with the GSource, so we need to * destroy() it */ g_source_destroy(source); /* We need to unref() the GSource to end the last reference * we got */ g_source_unref(source); /* The main loop should be destroyed before the context */ g_main_loop_unref(main_loop); /* Finally, destroy the context */ g_main_context_unref(context); /* Done! */ return 0; }