[fpc-devel] Safely shareable objects

José Mejuto joshyfun at gmail.com
Thu Jun 30 17:50:13 CEST 2011


Hello FPC,

Thursday, June 30, 2011, 4:07:22 PM, you wrote:

HPD> Now we can assume that IShareable objects/references can be used all
HPD> over the code, with no further precautions in explicit code required,
HPD> that the use of the object *and* its content is always synchronized and
HPD> sequentialized properly. Specific interfaces can be derived from 
HPD> IShareable, e.g. IShareableList, 
HPD> IShareableParamsAndResult<for_whatever_purpose>.

So you mean that something like:

IMyObject inherited from IShareable the compiler must add stub code on
each function/procedure/property to lock the interface ?

So a function like:

function iMyObject.Increment(a: integer): integer;
begin
  a:=a+1;
end;

must be "silently modified" by the compiler to something like:

function iMyObject.Increment(a: integer): integer;
begin
  IObjectCritical.Enter;
  try
    a:=a+1;
  finally
    IObjectCritical.Leave;
  end;
end;

????????????? To me it looks extremelly overkill.

If you think in the other approach, so when interface count is higher
than one enter the critical section, it could not be done IMHO because
when refcount reach 2 it could happend in thread 2 while thread 1 is
inside a procedure of the object which could lead to unexpected
results.

Maybe I missed something ?

-- 
Best regards,
 José




More information about the fpc-devel mailing list