GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Aug 25, 2016 1:10 pm

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: g_cond_timed_wait question
PostPosted: Sun Jun 15, 2008 9:54 pm 
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
I am a bit confused:

g_cond_timed_wait(*Cond, *mutex, *abs_time) is used mostly in threads to wait either until the Cond is signaled or wait time (abs_time) expired.
In the definition of this function the documentation says:
"...the mutex is unlocked before falling asleep and locked again before resuming...". This is obvious, so the mutex in the other thread would unloc while this thread is sleeping.
Now in many code examples I see this:
        g_mutex_lock (data_mutex);       
        IfOKresponse = g_cond_timed_wait(my_cond, data_mutex, &end_time);
        g_mutex_unlock (data_mutex);

That is, they lock the mutex just before g_cond_timed_wat() to be unlocked by the g_cond_timed_wait function right away.

Does it make sense?

 Post subject:
PostPosted: Wed Jun 25, 2008 9:32 pm 
GTK+ Guru

Joined: Thu Jun 21, 2007 1:52 pm
Posts: 198
Location: Wilkes Barre Pa
GThread is just a wrapper for Pthread i prefer to use pthreads because its a fully specified standard that is independent of any particular platform. Besides you find much more documentation for Pthreads.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: Google [Bot] and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group