[Lazarus] LCL messaging system SendMessage and Multi-Threads
Michael Schnell
mschnell at lumino.de
Fri May 7 15:36:03 CEST 2010
On 05/07/2010 03:18 PM, Andrew Brunner wrote:
> Ok. I'm familiar with Synchronize methods but wasn't sure if they were
> actually executed via the Main Thread and could truly solve the GUI
> concerns (especially on Linux but even on OSX and Windows).
>
That is what Synchronize has been invented for: Execute some of the
thread code in the main thread.
When calling Synchronize the thread stop at this point. the synchronized
method is scheduled to be executed in the main thread. When (after a
possibly very long time) the main thread is ready to execute that
method, it does so and after that wakes up the thread.
Advantage: you don't need to bother about protecting resources used both
by the main worker thread and the thread.
Disadvantage: the worker thread might stop for a very long time.
To prevent the thread from stopping, PostMessage() can be used and the
"synchronized" Method now is defined by procedure ... message in of some
Form.
Disadvantage: you need to take care of protecting commonly used resources.
-Michael
More information about the Lazarus
mailing list