Re: Thread safety



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 ]

But you have to make sure, that the information you pass around between the
threads is protected properly. But that has nothing to do with GLib/GTK/GDK
and is beyond the scope of this newsgroup.

Bye,
Sebastian
-- 
Sebastian Wilhelmi
mailto:wilhelmi ira uka de
http://goethe.ira.uka.de/~wilhelmi




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