Re: Multi-threading



On Wednesday 05 April 2006 21:32, Douglas C. MacKenzie wrote:
> I agree with the "common trap" assessment.
>
> I have my own semaphore that is poorly named "gtk_lock"
> that I use to synchronize access to gtk from my threads.
> My problem is trying to get a main thread to block for events
> without holding MY semaphore, then grab it and process
> the events.
>
> I'm now thinking I really should just use the GTK semaphore.
> I will read up on the g_thread_enter and g_thread_leave calls.
>

It is at http://developer.gnome.org/doc/API/2.0/gdk/gdk-Threads.html .  The 
point to note (as Paul Davis mentioned) is that all callbacks from GTK+ 
signals are already within the lock (you don't call gdk_thread_enter() and 
gdk_thread_leave()).  Callbacks from glib events (timeouts, giochannel events 
and the like) are not with the lock, so you need to invoke the GDK lock 
explicitly.

It is easier in my opinion to exercise the discipline that nothing calls a 
GTK+ function except the main program thread, and all the other threads post 
events to it (eg by using Glib::Dispatcher).  glib/glibmm are thread safe, so 
you are OK with them in any thread (provide you have called 
Glib::thread_init() or g_thread_init()).

Chris




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