[Lazarus] IUnknown and reference counting

Sven Barth pascaldragon at googlemail.com
Thu Mar 21 20:41:14 CET 2013


Am 21.03.2013 18:58 schrieb "Hans-Peter Diettrich" <DrDiettrich1 at aol.com>:
>
> Sven Barth schrieb:
>
>> Am 21.03.2013 15:22, schrieb Kostas Michalopoulos:
>>>
>>> What i'm thinking right now is to simply create the lightmap objects
(as interfaces) from the lightmapper side and send them to the 3D world
side. My only concern for now is if interfaces are thread safe (that is,
what happens if two threads keep a reference for the same object) or i need
to do my own locking.
>>
>> "TInterfacedObject" uses "InterlockedIncrement" and
"InterlockedDecrement" to manage the reference count. So on platforms where
these two are implemented in a thread safe manner it should be safe to use
interfaces in multiple threads.
>
>
> No :-(
>
> The same considerations apply to the use of object and interface
references in threads. Interface methods are implemented by class methods,
and consequently must not be called from multiple threads at the same time.

Kostas did not write about calling methods, but keeping references. And
here the reference counting mechanism can be considered threadsafe.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20130321/25833a35/attachment-0003.html>


More information about the Lazarus mailing list