[Lazarus] A few questions on threads

Michael Schnell mschnell at lumino.de
Tue Oct 4 13:11:03 CEST 2011


On 10/04/2011 12:53 PM, Frank Church wrote:
>
> I am looking at Application.QueueAsyncCall and the only parameter it 
> takes in addition to the method pointer is a PrtInt. That seems to 
> limit the options passed compared with TThread.Synchronize. Can the 
> PtrInt be cast to a pointer to a richer data structure?

TThread.Synchronize allows for no parameter at all. So QueueAsyncCall is 
less limited.

The parameter of course can be a pointer to a record or an object that 
might hold any information.

But you need to be aware that, while the pointer itself is "safe" (i.e. 
it does not change when arriving at the main thread even if the sending 
thread changes the value of the variable it gave to QueueAsyncCall), 
this of course is not true for the information the pointer points to. 
Here you might need to create a copy (by "New()" or ".Create") if the 
threads goes on writing to the original and you need to see a consistent 
object in the main thread. (beware of Strings doing reference counting 
here!)

"Synchronize" stalls the thread while doing the AsyncCall, so this 
problem does not arise.

-Michael




More information about the Lazarus mailing list