[Lazarus] GTK2 threading

Anton Kavalenka anton.k at tut.by
Thu Apr 4 16:48:12 CEST 2013


On 04.04.2013 17:22, Anton Kavalenka wrote:
> test application from http://bugs.freepascal.org/view.php?id=24120
>
> Addit XInitThreads to the initialiization section of second unit after 
> cthreads allows the test application start.
>
> Funny enough that the windows approach - sending a message (message 
> would be delivered in a window thread context) does not work  here.
>
> WinaAPI approach:
>
> InvalidateRect(Display.Handle, nil, false); // notify window regions 
> on invalidation
> Display.Update; // let the window process its messages
>
> delivers LCL message in context of calling thread.
>
> the only way - TThread.Synchronize(nil,Display.Refresh);
>
> IMO queuing LCL message into main thread message queue can resolve 
> lots of bugs.
>
> BTW: Moving mouse over the checkbox and button sometimes display their 
> text in the coloured painted rectangles.
>
> regards,
> Anton
http://docencia.etsit.urjc.es/moodle/pluginfile.php/1668/mod_folder/content/1/Slides/GNOME/threads.pdf?forcedownload=1

Multithread programming in GLib/GTK+
GLib is thread-safety when g_thread_init is used
GDK provides gdk_threads_init too that has to be used in
addition to g_thread_init, but it's not always
recommendable
Two options:

  * Using *gdk_threads_init*, *gdk_threads_enter()* and *gdk_threads_leave*
  * Accessing the program GUI exclusively from the main thread (where
    the gtk main loop is running)

The second options is preferable in most of the cases

Anton


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20130404/9b20650f/attachment-0003.html>


More information about the Lazarus mailing list