Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-07

What is the difference between TThread.Queue(aMethod: TThreadMethod) and Application.QueueAsyncCall(AMethod: TDataEvent; Data: PtrInt);

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dennis

Apart from the TThreadMethod and TDataEvent, what are the major differences? Are both of them thread safe to call from non-main thread? Will both of them overwrite some queue or buffer if the queues are full?

I tried to study the source code but I cannot find the implementation parts. I only find the interface parts of TThread classesh.inc

Dennis

Michael Van Canneyt
to Dennis
Dennis wrote 6 lines
Apart from the TThreadMethod and TDataEvent, what are the major differences? Are both of them thread safe to call from non-main thread? Will both of them overwrite some queue or buffer if the queues are full? I tried to study the source code but I cannot find the implementation parts. I only find the interface parts of TThread classesh.inc

To the best of my knowledge:

Application.QueueAsyncCall has nothing to do with threads. This is an LCL method which can be used to insert a callback in the message loop. I think it unlikely that this is thread-safe, I suspect it is only for the main thread.

TThread.Queue schedules a call for execution in the main thread. It is meant for use in other threads.

Michael.

Henry Vermaak
to Michael Van Canneyt
Michael Van Canneyt wrote 15 lines
On Fri, 1 Jul 2016, Dennis wrote: >Apart from the TThreadMethod and TDataEvent, what are the major >differences? Are both of them thread safe to call from non-main >thread? Will both of them overwrite some queue or buffer if the >queues are full? > >I tried to study the source code but I cannot find the implementation >parts. I only find the interface parts of TThread classesh.inc To the best of my knowledge: Application.QueueAsyncCall has nothing to do with threads. This is an LCL method which can be used to insert a callback in the message loop. I think it unlikely that this is thread-safe, I suspect it is only for the main thread.

It should be thread safe (see lazarus r31143). Works OK for me when called from threads.

Henry

Mattias Gaertner
to Michael Van Canneyt: To the best of my knowledge: Application.QueueAsyncCall has nothing to do with threads.…
Show quoted text 5 lines
[...] Application.QueueAsyncCall has nothing to do with threads. This is an LCL method which can be used to insert a callback in the message loop. I think it unlikely that this is thread-safe, I suspect it is only for the main thread.

It is thread-safe and the callback is called by the main thread.

TThread.Queue schedules a call for execution in the main thread. It is meant for use in other threads.

Mattias