[fpc-devel] Safely shareable objects

Hans-Peter Diettrich DrDiettrich1 at aol.com
Fri Jul 1 04:22:51 CEST 2011


José Mejuto schrieb:

>>> IMyObject inherited from IShareable the compiler must add stub code on
>>> each function/procedure/property to lock the interface ?
> 
> HPD> No. The object is locked as long the code holds the reference to it.
> 
> In that case read my note at the end of the e-mail, I think it could
> not be done in that way.

No other thread can have a reference to the same object, and 
consequently cannot call its methods.

_AddRef:
   if RefCount > 0 then
     EnterCriticalSection(myCS);

This will block any other thread in the attempt to get another 
reference, until the thread owning myCS has left the critical section.

DoDi




More information about the fpc-devel mailing list