[Lazarus] IUnknown and reference counting

Hans-Peter Diettrich DrDiettrich1 at aol.com
Thu Mar 21 18:39:28 CET 2013


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.

DoDi





More information about the Lazarus mailing list