RFC: reference counted Throwable
Ola Fosheim Grostad via Digitalmars-d
digitalmars-d at puremagic.com
Sat Sep 20 15:30:44 PDT 2014
On Saturday, 20 September 2014 at 22:07:45 UTC, Walter Bright
wrote:
> On 9/20/2014 11:26 AM, "Ola Fosheim Grøstad"
> <ola.fosheim.grostad+dlang at gmail.com>" wrote:
>> On Saturday, 20 September 2014 at 18:18:05 UTC, Walter Bright
>> wrote:
>>>
>>> Please show me the inc/dec optimized x86 code.
>>
>> There's no optimization of the inc/dec, you use regular
>> inc/dec within a larger
>> xbegin/xend block.
>>
>> You amortize the cost over all the lock-prefixed instructions
>> you would
>> otherwise have executed in that block. There is no locking,
>> there is a
>> transaction instead. Only if the transaction fails do you
>> execute the locking
>> fallback code.
>
> I strongly suggest taking a look at C++ shared_ptr<T>, compile
> a simple example, and examine the generated code. It is NOT AT
> ALL as simple as emitting an inc/dec pair. I.e. what happens if
> an exception is thrown between the inc and the dec?
C++ provides weak references. If you throw issue xabort.
Nobody have said it is free, and TSX is new tech. So what you can
do, who knows?
> If RC was as costless and simple as you are suggesting,
> everyone would be doing it and would have for decades.
Transactions are not free.
> Now embed that object as a field in some other object.
Uhm, I referred to new-allocated objects.
> Now add that runtime distinguishing logic to the inc/dec code.
Test N flag?
More information about the Digitalmars-d
mailing list