Re: g_threads_enter() equivalent



On Sat, 8 May 2010 15:48:30 +0200 (CEST)
Mark Roberts <gtkmm manumark de> wrote:
> > This is wrong.  gdk_threads_enter() and gdk_threads_leave() lock and
> > unlock the GDK global lock.  You cannot replace that with a mutex of
> > your own, because you cannot control what happens in main loop
> > events with such a mutex.  You have to use the lock which GDK uses,
> > namely its global lock.
> 
> Thanks for the clarification. I did not mean to say that 
> gdk_threads_enter() and gdk_threads_leave() could be replaced by any
> of the utility classes mentioned in my post, but it may have seemed
> that that was what I meant.
> 
> I only meant that you can generally sink a pair of functions in a
> utility class so as not to forget calling one of them.

Ah yes.  If programing in C++ using the C API and the GDK global lock,
it would be wise to use a scoped handle class which does the locking
and unlocking for you.

Personally though I don't program multi-threaded applications that way,
and prefer message passing between main loops (something that you
cannot do with the glibmm implementation because it is not thread safe,
but you can reasonably trivially write your own thread-safe wrapper for
sources obtained with g_idle_source_new() that can do more or less
anything you want).

Chris


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