[Lazarus] Threads

Antonio Fortuny a.fortuny at sitasoftware.lu
Fri Mar 23 11:33:29 CET 2012


Many thanks Dodi.

Antonio.

Le 23/03/2012 10:59, Hans-Peter Diettrich a écrit :
> Antonio Fortuny schrieb:
>
>> Trying to be as much clear as possible, there are some sentences:
>>
>> Assuming this few statements (aka my own rules when writing thread's 
>> code):
>> a. all thread code+data are encapsulated into a TThread object
>> b. "Thread safe" means that there is no overlap of data references 
>> from thread to thread, the main thread inclusive, and that no 
>> references are passed outside the thread's control from thread to 
>> thread (by the means of the owner or global vars for instance)
>> c. the thread creator does not interfere in any way with the thread's 
>> data and methods as soon as the thread has been started (Terminated 
>> execpted of course)
>> d. no function neither procedure calls are made to any function or 
>> procedure defined outside of the thread control (aka self defined 
>> methods)
>
> Looks good :-)
>
>> Do you all agree on the following asserts:
>> 1. All variables in the thread definition (TThread's private, 
>> protected and public variables) are "Thread safe" BUT are accessible 
>> to the thread creator
>
> The OPL visibility rules apply. Public members are accessible by 
> everybody, others only from inside the unit where the thread class is 
> declared. As long as the thread creator doesn't export the thread 
> object, nobody else can access it, of course.
I agree with you that the assertion could be more precise when talking 
about object members visibility. But we are talking abount  OOP, aren't 
we ? 8-)
>
>
>> 5. all useful code a thread needs should be encapsultated into a 
>> TObject descendant and instantiated within the thread's space.
>
> This can all be implemented in the derived TThread class.
So, building an object around this utility code does not enlarge thread 
safety ?
>
>> 6. all methods defined in the thread's definition, aprat from the 
>> EXECUTE procedure (obvious !), run into the  thread creator space 
>> (the one which instantiates the thread, aka does something like 
>> wThread := TMyThread.Create (False) )
>
> Every procedure or method runs in the context of its *caller*. 
> Everything called from the thread's Execute method executes in the 
> thread context (stack, threadvars).
Sounds very clear. Big idea using few words. I appeciate.
>
> DoDi
>
>
> -- 
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>






More information about the Lazarus mailing list