Hi,
I was looking for a solution how to go back from the main thread to the some other thread, and I found a good example for this on the gtk site. I am just wondering is there a way to do this (go back from the main thread to the some other thread) without any use of mutex, and with less code lines, but to keep that - signal will not be emitted before wait function. Any suggestion?
Ivana
http://www.gtk.org/api/2.6/glib/glib-Threads.html#g-cond-waitExample 9:
Code:
GCond* data_cond = NULL; /* Must be initialized somewhere */
GMutex* data_mutex = NULL; /* Must be initialized somewhere */
gpointer current_data = NULL;
void push_data (gpointer data)
{
g_mutex_lock (data_mutex);
current_data = data;
g_cond_signal (data_cond);
g_mutex_unlock (data_mutex);
}
gpointer pop_data ()
{
gpointer data;
g_mutex_lock (data_mutex);
while (!current_data)
g_cond_wait (data_cond, data_mutex);
data = current_data;
current_data = NULL;
g_mutex_unlock (data_mutex);
return data;
}