How to invoke a function in main loop context

#include <glib.h>
    
/*this function shall be invoked in main loop context*/    
gboolean _main_loop_context_callback(void *cb_data)
{
	//return TRUE;   //main loop idle source will be invoked multiple times
	
	//return FALSE;  //main loop idle source will be invoked just once.

}

/*This function may be executing in any subthread context*/
/*g_idle_add_full will execute the _main_loop_context_callback function in main loop context*/
int thread1(void* user_data)
{
    // .. .....
	g_idle_add_full(G_PRIORITY_DEFAULT, _main_loop_context_callback, cb_data, NULL);
}

Responses

0 Replies