Re: XInitThreads causing problems to GTK windows.



Hi, Peter

>       Can someone tell me if there's something I need to know before calling
> Xlib code directly, within GTK programs? I'm trying to write a proggy that
> will have one thread that does some graphics stuff, talking directly to XLib
> (with it's own connection to the X server). Because that means that there
> might
> be two threads calling XLib concurrently I need to call XInitThreads() -
> it's
> man page states..:-
> 
>         This function must be the first Xlib
>         function a multi-threaded program calls,
>         and it must complete before any other
>         Xlib call is made.
> 
>         However - I've found that if I call XInitThreads BEFORE gtk_init,
> then
> pressing a key with a fileselection on the screen causes the program to hang
> somewhere inside gtk_main_iteration().
> 
>     If I call XInitThreads after gtk_init then everything appears fine, but
> I don't know what affects that'll have on XLib. I'm not really too bothered
> about GTK / GDK or GLIB being thread safe - the second thread need not call
> any of those functions. But I've tried inserting g_threads_init() here and
> there, without any luck.
> 
>         Anyone have any ideas?
 
From the XInitThreads() manpage

       It is only necessary to call this function if multiple
       threads might use Xlib concurrently.  If all calls to Xlib
       functions are protected by some other access mechanism
       (for example, a mutual exclusion lock in a toolkit or
       through explicit client programming), Xlib thread initial­
       ization is not required.  It is recommended that single-
       threaded programs not call this function.


And the gtk+/docs/

   - You must call g_thread_init() before executing any
     other GTK+ or GDK functions in a threaded GTK+ program.
			...
     As always, you must also surround any calls to GTK+
     not made within a signal handler with a 
     gdk_threads_enter()/gdk_threads_leave() pair.

So 'all calls to Xlib functions are protected by some other access mechanism',
so youu don't need to call XInitThreads.

Bye,
Sebastian

PS.: It is however possible, that the use of XThreadsInit() exposes a bug in
GTK+, so I'll have a look at your prog anyway.

-- 
Sebastian Wilhelmi                   |            här ovanför alla molnen
mailto:wilhelmi@ira.uka.de           |      är himmlen så förunerligt blå
http://goethe.ira.uka.de/~wilhelmi   |



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