<p>Am 20.09.2014 20:34 schrieb "Giuliano Colla" <<a href="mailto:giuliano.colla@fastwebnet.it">giuliano.colla@fastwebnet.it</a>>:<br>
><br>
><br>
> Il 20/09/2014 19:20, Boian Mitov ha scritto:<br>
>><br>
>> Hi Chriss,<br>
>> <br>
>> Personally I favor reference counted objects. While there are interfaces as you pointed, and in Delphi you can even use smart pointers now, there is still a lot of cases when you need to use objects, and have to manually free them.<br>
>> In single threaded environment that is not such an issue, but in parallel and heavily multithreaded environments, reference counting is a life saver.<br>
><br>
><br>
> Can you explain how reference counting can be safely implemented in a parallel multithreaded environment, without heavily affecting performance?<br>
> A mere increment or decrement of count means to get a lock and to release a lock on that object. Application code can know what is thread safe and what is not, and use lock only when appropriate.<br>
> A general mechanism to be reliable should take into account all possibilities. If it does, it will block threads even when unnecessary. If it doesn't, it will be unsafe.</p>
<p>That would work the same way as it does in interfaces, arrays and strings: using Interlocked*-functions.</p>
<p>Regards,<br>
Sven</p>