Hi everyone,

Thank you very much for your help on my previous Exception threadsafety question!

Another threadsafe problem just poped in my mind.

The TInterfacedObject provides default referencing couting support, which uses Interlocked_ operations that seems to be threadsafe. However, I think there still is a race condition in the following scenario:

0. An interface, "IntfA", implemented by a TInterfacedObject descendant has refcount 1; 1. A thread, "threadA", makes another reference to 'IntfA', however, the execution is interrupted just before the InterlockedIncrement() in _AddRef; 2. Another thread dereferences "IntfA", the instance's refcount drops to 0 and is destroyed.
3. Execution of "threadA" resumes, but the instance is no longer there!

I think I am being paranoid again, and please tell me yes! (otherwise life is going to be very miserable...)

AdamWu

----
.dlrow eht htiw thgir s'lla ,nevaeh sih ni si doG

_________________________________________________________________
享用世界上最大的电子邮件系统― MSN Hotmail。 http://www.hotmail.com
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to