[Lazarus] Application.QueueAsyncCall()
cobines
cobines at gmail.com
Wed Jan 20 20:54:23 CET 2010
2010/1/20 Brad Campbell <brad at wasp.net.au>:
> Is QueueAsyncCall() threadsafe?
As far as I know it is not.
>
> Let's say I have a communications child thread and I want to trigger a call
> back in the main GUI thread. Traditionally I'd do something ugly like have a
> timer polling a variable used as a flag, or polling a RtlEvent on a short
> timeout, but this seems like a much nicer solution.
>
You can call TThread.Synchronize(), your thread will be stopped until
the GUI thread executes your function.
Other solution is to create a separate thread for handling such GUI
functions (take a look at attached source); this doesn't stop your
child thread. Be careful however because in this case you don't
control when your method is called (it may be after your thread is
already finished).
> Also, is there any form of mutex or lock I can use to protect access to a
> linked list shared between threads? It would appear that RTLCriticalSection
> might do what I want.
Yes, it will do fine. The TCriticalSection is just a wrapper over
RTLCriticalSection.
--
cobines
-------------- next part --------------
A non-text attachment was scrubbed...
Name: uGuiMessageQueue.pas
Type: text/x-pascal
Size: 5139 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20100120/74721502/attachment-0002.pas>
More information about the Lazarus
mailing list