[Lazarus] Threads
Antonio Fortuny
a.fortuny at sitasoftware.lu
Thu Mar 22 15:32:37 CET 2012
Hi folks.
Wen launching a thread, the process responsible for the thread object
creation and the call to TThread.Start and the thread EXECUTE procedure,
run in parallel. That's why the SYNCHRONIZE procedure exists and that
the developer has to pay attention to not share code between threads.
So far, so good.
Now imagine that the EXECUTE procedure of a thread creates a useful
object (TMyObject) with properties and methods. This thread is launched
half a dozen times to process half a dozen simultaneous operations.
My question is:
How the properties and methods of the TMyObject created in every
launched thread are they managed from one thread to another. As far as
the data segment is concerned, no problem, I guess that every instance
of the TMyObject has its own data in its thread address space: no mix.
But what about the code and the local methods stack: will it be shared ?
And if answer is yes, to what should I take care ?
The question is far from trivial: I try to keep the EXECUTE procedure as
small as possible and spread the code and data over a number of
specialized units avoiding to load the EXECUTE procedure stack with
heavy data ans structures.
I apologize if my question doesn't sound very clear, but it's not even
clear in my mind :-[
Antonio.
More information about the Lazarus
mailing list