Re: Thread safety



Sebastian Wilhelmi <wilhelmi ira uka de> writes:

> Hi Ed,
> 
> > In a previous post, I mentioned using kernel 2.4 because of its
> > handling of pthreads.  I received some cautionary messages regarding
> > using more than 1 thread in the user interface.  My hardware simulator
> > project requires realtime interfacing with a particular parallel
> > interface card, for which I must create a device driver.  It also has a
> > fairly extensive user interface, created in Gtk+ with Glade.  I have it
> > in mind that the device driver will handle reading complete messages
> > from the interface, storing them in some message area as integer
> > numbers, then set a signal to the user interface thread to cause the
> > widgets which display recieved messages to be updated with the received
> > contents.  I also have created
> > a message building widget group which allows creation of messages, and
> > uses a Send button to inform the device driver to send the message.  I
> > suppose that this action will cause a call to the driver to accomplish
> > the sending.   Could someone please explain the dangers of this
> > multi-threaded approach?  And, what I must do or could do to remove or
> > reduce the risks/problems?  
> 
> Simply put: As long as you use GTK and GDK functions only from one thread,
> you're save. You have to initialize GLib thread system though, if you plan on
> using GLib is multiple threads. This is done by calling g_thread_init (NULL);
> 
> [ This is not to say that there isn't a method of using GTK in multiple   
>   threads, indeed there is, see the GTK FAQ ]
 
Actually, if you call g_thread_init (), you _must_ call gdk_threads_enter(),
gdk_threads_leave() as described in the FAQ, though you can get away
within surrounding the entire GUI part of your program with a single
such call.

                                          Owen




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