Re: Documentation question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi again,

	I've been shown that was in an error. g_cond_wait unlocks data_mutex (I
didn't notice that) and locks it again just before returning, so the
example code works perfectly.

	I'm sorry for the mess O:)

Saludos

El jue, 14-10-2004 a las 10:40, Eneko Lacunza escribió:
> --- cut ---
> Example 9. Using GCond to block a thread until a condition is satisfied
> 
> 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;
> }
> --- cut ---
> 
> Each of the function is to be called from a different thread. I think
> the example causes a deadlock, because when the first pop_data() stops
> waiting in g_cond_wait, data_mutex is locked, so push_data would never
> get the lock for it, an thus will never g_cond_signal so that pop_data
> exits the waiting state.
> 
> I'd like to know if I'm correct. If not, please I'd like to know why. If
> correct, where should I report this bug?
> 
> Thanks a lot!
-- 
Eneko Lacunza
O.D.E. Office
Panda Software - Bilbao (Spain) - http://www.pandasoftware.es
_______________________________________________

gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list


[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux