Re: linux vs. win32: gdk_threads_enter behaving different



Felix Kater writes:
So, my conclusion: On the contrast to linux, unter win32 there is no way
to use gdk_threads_enter() to synchronize between different threads.

Are you sure that it's gdk_threads_enter itself that blocks? Then your
first problem might be that you don't call gdk_threads_enter before
calling gtk_init() and gtk_main()? See
http://bugzilla.gnome.org/show_bug.cgi?id=426729#c3 and the following
comments, and read the sample program in
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Threads.html closely.

But even if you do that, you might get past the gdk_threads_enter()
call, but you will notice that then some of the actual GDK calls that
manipulate windows will hang.

As such gdk_threads_enter() does work (it after all does nothing
except locks a GMutex, and GMutexes work fine on Win32). But, calling
GDK functions that actually call Win32 window manipulation functions
from different threads will not work on Win32. You will get deadlocks
or other bugs.

My workaround: The thread itself calls g_idle_add() to do the job.

That is the recommended way, yes. Do all GTK+ calls in the main tread.

So, my conclusion: On the contrast to linux

You mean in contrast to X11. Linux is just one platform running X11

unter win32 there is no way to use gdk_threads_enter() to
synchronize between different threads.

See above. The problem isn't the thread synchronization wouldn't work
(gdk_threads_enter/leave() just lock and unlock a GMutex, and that
should work fine as long as you balance the lock/unlocks
correctly).

The problem is that even if you synchronize GDK calls between threads,
you will get deadlocks. The Win32 window handling is very
thread-aware. (Compare to X11 which is a network protocol. The X
server knows nothing about threads in the client application.)
Messages ("events" in X11 parlance) related to a window are delivered
to the thread that created the window, for instance. And only the main
thread in a GTK+ program is looking for messages. Etc.

--tml



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