Is this thread-safe?

Giganews Newsgroups
Subject: Is this thread-safe?
Posted by:  Arno Garrels (firstname.name@nospam-gmx.de)
Date: Sat, 22 Jun 2013

{code}
function TObject.__ObjRelease: Integer;
begin
  Result := AtomicDecrement(FRefCount) and not objDisposedFlag;
  if Result = 0 then
  begin
    __MarkDestroying(Self);
    if __SetDisposed(Self) then
      Destroy
    else
      FreeInstance;
  end;
end;
{code}

Well, AtomicDecrement actually is, however what follows after
AtomicDecrement returned zero is not. If after AtomicDecrement
returned zero another thread would increment the reference count
we got a nice little dangling pointer.
Or am I missing something?

--
Arno

Replies