Jump to page: 1 25  
Page
Thread overview
[phobos] Fwd: Re: Ruling out arbitrary cost copy construction?
Oct 31, 2010
Shin Fujishiro
Nov 01, 2010
Masahiro Nakagawa
Nov 01, 2010
Michel Fortin
Nov 01, 2010
David Simcha
Nov 02, 2010
Sean Kelly
Nov 01, 2010
Michel Fortin
Nov 01, 2010
David Simcha
Nov 01, 2010
Michel Fortin
Nov 01, 2010
David Simcha
Nov 01, 2010
Robert Jacques
Nov 01, 2010
David Simcha
Nov 01, 2010
Robert Jacques
Nov 02, 2010
Sean Kelly
Nov 02, 2010
David Simcha
Nov 01, 2010
Brad Roberts
Nov 01, 2010
Brad Roberts
Nov 02, 2010
Sean Kelly
Nov 02, 2010
Sean Kelly
Nov 02, 2010
SHOO
Nov 02, 2010
Michel Fortin
Nov 03, 2010
SHOO
Nov 03, 2010
Jonathan M Davis
Nov 04, 2010
SHOO
Nov 04, 2010
SHOO
Nov 03, 2010
Max Samukha
Nov 04, 2010
SHOO
Nov 03, 2010
Max Samukha
Nov 03, 2010
David Simcha
Nov 04, 2010
Max Samukha
Nov 03, 2010
Michel Fortin
Nov 04, 2010
Max Samukha
October 30, 2010
I am highly interested in the opinion of Phobos contributors in the matter of copy construction (just posted the message below).

Andrei

-------- Original Message --------
Subject: Re: Ruling out arbitrary cost copy construction?
Date: Sat, 30 Oct 2010 22:56:24 -0500
From: Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>
Newsgroups: digitalmars.D

On 10/30/2010 09:40 PM, Michel Fortin wrote:
> On 2010-10-30 20:49:38 -0400, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> said:
>
>> On 10/30/10 2:24 CDT, Don wrote:
>>> At the moment, I think it's impossible.
>>> Has anyone succesfully implemented refcounting in D? As long as bug 3516
>>> (Destructor not called on temporaries) remains open, it doesn't seem to
>>> be possible.
>>> Is that the only blocker, or are there others?
>>
>> I managed to define and use RefCounted in Phobos. File also uses hand-made reference counting. I think RefCounted is a pretty good abstraction (unless it hits the bug you mentioned.)
>
> I like the idea of RefCounted as a way to automatically make things reference counted.

Unfortunately it's only a semi-automated mechanism.

> But like File and many similar ref-counted structs, it has this race condition (bug 4624) when stored inside the GC heap. Currently, most of Phobos's ref-counted structs are race-free only when they reside on the stack or if your program has only one thread (because the GC doesn't spawn threads if I'm correct).
>
> It's a little sad that the language doesn't prevent races in destructors
> (bug 4621).

I hope we're able to solve these implementation issues that can be seen as independent from the decision at hand.

Walter and I discussed the matter again today and we're on the brink of deciding that cheap copy construction is to be assumed. This simplifies the language and the library a great deal, and makes it perfectly good for 95% of the cases. For a minority of types, code would need to go through extra hoops (e.g. COW, refcounting) to be compliant.

I'm looking for more feedback from the larger D community. This is a very important decision that marks one of the largest departures from the C++ style. Taking the wrong turn here could alienate many programmers coming from C++.

So, everybody - this is really the time to speak up or forever be silent.


Andrei
November 01, 2010
I think cheap copy construction is must.  Since any accesses to sealed range elements involve copy construction.

I read older discussions and found that they mostly focused on swap and moveX.  But the problem lies not only in the swap operation.  It's everywhere and move doesn't help.

Note that *every* access to an element of sealed range involves a copy construction.  When sorting a sealed range of BigInts (Array!BigInt), even an innocent comparison creates two BigInt copies:

    if (!less(r[i], r[p]))  // Creates two temporary copies.

I think these copies can't be elided since original objects exist in a container at the same time.  Still the compared elements could be moved out and then assigned back, but that's terribly awkward.

We mostly don't want to move out elements - just want to read them. Sealed ranges are inherently copy intensive, so if you will put forward the concept, copy cost of elements must be assumed to be cheap IMO.


Shin

Andrei Alexandrescu <andrei at erdani.com> wrote:
> I am highly interested in the opinion of Phobos contributors in the matter of copy construction (just posted the message below).
> 
> Andrei
> 
> -------- Original Message --------
> Subject: Re: Ruling out arbitrary cost copy construction?
> Date: Sat, 30 Oct 2010 22:56:24 -0500
> From: Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>
> Newsgroups: digitalmars.D
> 
> On 10/30/2010 09:40 PM, Michel Fortin wrote:
> > On 2010-10-30 20:49:38 -0400, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> said:
> >
> >> On 10/30/10 2:24 CDT, Don wrote:
> >>> At the moment, I think it's impossible.
> >>> Has anyone succesfully implemented refcounting in D? As long as bug 3516
> >>> (Destructor not called on temporaries) remains open, it doesn't seem to
> >>> be possible.
> >>> Is that the only blocker, or are there others?
> >>
> >> I managed to define and use RefCounted in Phobos. File also uses hand-made reference counting. I think RefCounted is a pretty good abstraction (unless it hits the bug you mentioned.)
> >
> > I like the idea of RefCounted as a way to automatically make things reference counted.
> 
> Unfortunately it's only a semi-automated mechanism.
> 
> > But like File and many similar ref-counted structs, it has this race condition (bug 4624) when stored inside the GC heap. Currently, most of Phobos's ref-counted structs are race-free only when they reside on the stack or if your program has only one thread (because the GC doesn't spawn threads if I'm correct).
> >
> > It's a little sad that the language doesn't prevent races in destructors
> > (bug 4621).
> 
> I hope we're able to solve these implementation issues that can be seen as independent from the decision at hand.
> 
> Walter and I discussed the matter again today and we're on the brink of deciding that cheap copy construction is to be assumed. This simplifies the language and the library a great deal, and makes it perfectly good for 95% of the cases. For a minority of types, code would need to go through extra hoops (e.g. COW, refcounting) to be compliant.
> 
> I'm looking for more feedback from the larger D community. This is a very important decision that marks one of the largest departures from the C++ style. Taking the wrong turn here could alienate many programmers coming from C++.
> 
> So, everybody - this is really the time to speak up or forever be silent.
> 
> 
> Andrei
October 31, 2010
Alright, then how do we solve refcounting of constant objects (see Michel Fortin's question)? My solution involves casting away const and keeping immutability information at runtime. Is that acceptable?

Andrei

On 10/31/10 5:32 PM, Shin Fujishiro wrote:
> I think cheap copy construction is must.  Since any accesses to sealed range elements involve copy construction.
>
> I read older discussions and found that they mostly focused on swap and moveX.  But the problem lies not only in the swap operation.  It's everywhere and move doesn't help.
>
> Note that *every* access to an element of sealed range involves a copy construction.  When sorting a sealed range of BigInts (Array!BigInt), even an innocent comparison creates two BigInt copies:
>
>      if (!less(r[i], r[p]))  // Creates two temporary copies.
>
> I think these copies can't be elided since original objects exist in a container at the same time.  Still the compared elements could be moved out and then assigned back, but that's terribly awkward.
>
> We mostly don't want to move out elements - just want to read them. Sealed ranges are inherently copy intensive, so if you will put forward the concept, copy cost of elements must be assumed to be cheap IMO.
>
>
> Shin
>
> Andrei Alexandrescu<andrei at erdani.com>  wrote:
>> I am highly interested in the opinion of Phobos contributors in the matter of copy construction (just posted the message below).
>>
>> Andrei
>>
>> -------- Original Message --------
>> Subject: Re: Ruling out arbitrary cost copy construction?
>> Date: Sat, 30 Oct 2010 22:56:24 -0500
>> From: Andrei Alexandrescu<SeeWebsiteForEmail at erdani.org>
>> Newsgroups: digitalmars.D
>>
>> On 10/30/2010 09:40 PM, Michel Fortin wrote:
>>> On 2010-10-30 20:49:38 -0400, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>  said:
>>>
>>>> On 10/30/10 2:24 CDT, Don wrote:
>>>>> At the moment, I think it's impossible.
>>>>> Has anyone succesfully implemented refcounting in D? As long as bug 3516
>>>>> (Destructor not called on temporaries) remains open, it doesn't seem to
>>>>> be possible.
>>>>> Is that the only blocker, or are there others?
>>>>
>>>> I managed to define and use RefCounted in Phobos. File also uses hand-made reference counting. I think RefCounted is a pretty good abstraction (unless it hits the bug you mentioned.)
>>>
>>> I like the idea of RefCounted as a way to automatically make things reference counted.
>>
>> Unfortunately it's only a semi-automated mechanism.
>>
>>> But like File and many similar ref-counted structs, it has this race condition (bug 4624) when stored inside the GC heap. Currently, most of Phobos's ref-counted structs are race-free only when they reside on the stack or if your program has only one thread (because the GC doesn't spawn threads if I'm correct).
>>>
>>> It's a little sad that the language doesn't prevent races in destructors
>>> (bug 4621).
>>
>> I hope we're able to solve these implementation issues that can be seen as independent from the decision at hand.
>>
>> Walter and I discussed the matter again today and we're on the brink of deciding that cheap copy construction is to be assumed. This simplifies the language and the library a great deal, and makes it perfectly good for 95% of the cases. For a minority of types, code would need to go through extra hoops (e.g. COW, refcounting) to be compliant.
>>
>> I'm looking for more feedback from the larger D community. This is a very important decision that marks one of the largest departures from the C++ style. Taking the wrong turn here could alienate many programmers coming from C++.
>>
>> So, everybody - this is really the time to speak up or forever be silent.
>>
>>
>> Andrei
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


November 02, 2010
On Mon, 01 Nov 2010 13:21:23 +0900, Andrei Alexandrescu <andrei at erdani.com> wrote:

> Alright, then how do we solve refcounting of constant objects (see Michel Fortin's question)? My solution involves casting away const and keeping immutability information at runtime. Is that acceptable?

Your approach seems to be C++'s mutable. I am acceptable.

You said "There are several solutions possible" on digitalmars.D. Can you show the example of other solutions?

"the compiler knowing about the idiom" means Python-like approach? If so, I think such approach makes the compiler more complex :(


Masahiro

> On 10/31/10 5:32 PM, Shin Fujishiro wrote:
>> I think cheap copy construction is must.  Since any accesses to sealed range elements involve copy construction.
>>
>> I read older discussions and found that they mostly focused on swap and moveX.  But the problem lies not only in the swap operation.  It's everywhere and move doesn't help.
>>
>> Note that *every* access to an element of sealed range involves a copy construction.  When sorting a sealed range of BigInts (Array!BigInt), even an innocent comparison creates two BigInt copies:
>>
>>      if (!less(r[i], r[p]))  // Creates two temporary copies.
>>
>> I think these copies can't be elided since original objects exist in a container at the same time.  Still the compared elements could be moved out and then assigned back, but that's terribly awkward.
>>
>> We mostly don't want to move out elements - just want to read them. Sealed ranges are inherently copy intensive, so if you will put forward the concept, copy cost of elements must be assumed to be cheap IMO.
>>
>>
>> Shin
>>
>> Andrei Alexandrescu<andrei at erdani.com>  wrote:
>>> I am highly interested in the opinion of Phobos contributors in the matter of copy construction (just posted the message below).
>>>
>>> Andrei
>>>
>>> -------- Original Message --------
>>> Subject: Re: Ruling out arbitrary cost copy construction?
>>> Date: Sat, 30 Oct 2010 22:56:24 -0500
>>> From: Andrei Alexandrescu<SeeWebsiteForEmail at erdani.org>
>>> Newsgroups: digitalmars.D
>>>
>>> On 10/30/2010 09:40 PM, Michel Fortin wrote:
>>>> On 2010-10-30 20:49:38 -0400, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>  said:
>>>>
>>>>> On 10/30/10 2:24 CDT, Don wrote:
>>>>>> At the moment, I think it's impossible.
>>>>>> Has anyone succesfully implemented refcounting in D? As long as bug
>>>>>> 3516
>>>>>> (Destructor not called on temporaries) remains open, it doesn't
>>>>>> seem to
>>>>>> be possible.
>>>>>> Is that the only blocker, or are there others?
>>>>>
>>>>> I managed to define and use RefCounted in Phobos. File also uses hand-made reference counting. I think RefCounted is a pretty good abstraction (unless it hits the bug you mentioned.)
>>>>
>>>> I like the idea of RefCounted as a way to automatically make things reference counted.
>>>
>>> Unfortunately it's only a semi-automated mechanism.
>>>
>>>> But like File and many similar ref-counted structs, it has this race
>>>> condition (bug 4624) when stored inside the GC heap. Currently, most
>>>> of
>>>> Phobos's ref-counted structs are race-free only when they reside on
>>>> the
>>>> stack or if your program has only one thread (because the GC doesn't
>>>> spawn threads if I'm correct).
>>>>
>>>> It's a little sad that the language doesn't prevent races in
>>>> destructors
>>>> (bug 4621).
>>>
>>> I hope we're able to solve these implementation issues that can be seen as independent from the decision at hand.
>>>
>>> Walter and I discussed the matter again today and we're on the brink of deciding that cheap copy construction is to be assumed. This simplifies the language and the library a great deal, and makes it perfectly good for 95% of the cases. For a minority of types, code would need to go through extra hoops (e.g. COW, refcounting) to be compliant.
>>>
>>> I'm looking for more feedback from the larger D community. This is a very important decision that marks one of the largest departures from the C++ style. Taking the wrong turn here could alienate many programmers coming from C++.
>>>
>>> So, everybody - this is really the time to speak up or forever be silent.
>>>
>>>
>>> Andrei
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
November 01, 2010
Sounds reasonable iff we assume that ref counted stuff will never be shared across threads, which we seem to be assuming anyhow.

On Mon, Nov 1, 2010 at 12:21 AM, Andrei Alexandrescu <andrei at erdani.com>wrote:

> Alright, then how do we solve refcounting of constant objects (see Michel Fortin's question)? My solution involves casting away const and keeping immutability information at runtime. Is that acceptable?
>
> Andrei
>
>
> On 10/31/10 5:32 PM, Shin Fujishiro wrote:
>
>> I think cheap copy construction is must.  Since any accesses to sealed range elements involve copy construction.
>>
>> I read older discussions and found that they mostly focused on swap and moveX.  But the problem lies not only in the swap operation.  It's everywhere and move doesn't help.
>>
>> Note that *every* access to an element of sealed range involves a copy construction.  When sorting a sealed range of BigInts (Array!BigInt), even an innocent comparison creates two BigInt copies:
>>
>>     if (!less(r[i], r[p]))  // Creates two temporary copies.
>>
>> I think these copies can't be elided since original objects exist in a container at the same time.  Still the compared elements could be moved out and then assigned back, but that's terribly awkward.
>>
>> We mostly don't want to move out elements - just want to read them. Sealed ranges are inherently copy intensive, so if you will put forward the concept, copy cost of elements must be assumed to be cheap IMO.
>>
>>
>> Shin
>>
>> Andrei Alexandrescu<andrei at erdani.com>  wrote:
>>
>>> I am highly interested in the opinion of Phobos contributors in the matter of copy construction (just posted the message below).
>>>
>>> Andrei
>>>
>>> -------- Original Message --------
>>> Subject: Re: Ruling out arbitrary cost copy construction?
>>> Date: Sat, 30 Oct 2010 22:56:24 -0500
>>> From: Andrei Alexandrescu<SeeWebsiteForEmail at erdani.org>
>>> Newsgroups: digitalmars.D
>>>
>>> On 10/30/2010 09:40 PM, Michel Fortin wrote:
>>>
>>>> On 2010-10-30 20:49:38 -0400, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>  said:
>>>>
>>>>  On 10/30/10 2:24 CDT, Don wrote:
>>>>>
>>>>>> At the moment, I think it's impossible.
>>>>>> Has anyone succesfully implemented refcounting in D? As long as bug
>>>>>> 3516
>>>>>> (Destructor not called on temporaries) remains open, it doesn't seem
>>>>>> to
>>>>>> be possible.
>>>>>> Is that the only blocker, or are there others?
>>>>>>
>>>>>
>>>>> I managed to define and use RefCounted in Phobos. File also uses hand-made reference counting. I think RefCounted is a pretty good abstraction (unless it hits the bug you mentioned.)
>>>>>
>>>>
>>>> I like the idea of RefCounted as a way to automatically make things reference counted.
>>>>
>>>
>>> Unfortunately it's only a semi-automated mechanism.
>>>
>>>  But like File and many similar ref-counted structs, it has this race
>>>> condition (bug 4624) when stored inside the GC heap. Currently, most of Phobos's ref-counted structs are race-free only when they reside on the stack or if your program has only one thread (because the GC doesn't spawn threads if I'm correct).
>>>>
>>>> It's a little sad that the language doesn't prevent races in destructors
>>>> (bug 4621).
>>>>
>>>
>>> I hope we're able to solve these implementation issues that can be seen as independent from the decision at hand.
>>>
>>> Walter and I discussed the matter again today and we're on the brink of deciding that cheap copy construction is to be assumed. This simplifies the language and the library a great deal, and makes it perfectly good for 95% of the cases. For a minority of types, code would need to go through extra hoops (e.g. COW, refcounting) to be compliant.
>>>
>>> I'm looking for more feedback from the larger D community. This is a very important decision that marks one of the largest departures from the C++ style. Taking the wrong turn here could alienate many programmers coming from C++.
>>>
>>> So, everybody - this is really the time to speak up or forever be silent.
>>>
>>>
>>> Andrei
>>>
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
>>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20101101/3c036ce2/attachment.html>
November 01, 2010
Ref counting still has to be thread aware because anything allocated on the heap can be destroyed in any thread, even if the type is not shared.  I think that is Michel's point.  Even if you don't store the reference types on the heap, something that contains the reference could be stored on the heap (think of a File member of a class).

-Steve


>
>From: David Simcha <dsimcha at gmail.com>
>To: Discuss the phobos library for D <phobos at puremagic.com>
>Sent: Mon, November 1, 2010 11:33:19 AM
>Subject: Re: [phobos] Fwd: Re: Ruling out arbitrary cost copy construction?
>
>Sounds reasonable iff we assume that ref counted stuff will never be shared across threads, which we seem to be assuming anyhow.
>
>
>On Mon, Nov 1, 2010 at 12:21 AM, Andrei Alexandrescu <andrei at erdani.com> wrote:
>
>Alright, then how do we solve refcounting of constant objects (see Michel Fortin's question)? My solution involves casting away const and keeping immutability information at runtime. Is that acceptable?
>>
>>Andrei
>>
>>
>>On 10/31/10 5:32 PM, Shin Fujishiro wrote:
>>
>>I think cheap copy construction is must.  Since any accesses to sealed
>>>range elements involve copy construction.
>>>
>>>I read older discussions and found that they mostly focused on swap and moveX.  But the problem lies not only in the swap operation.  It's everywhere and move doesn't help.
>>>
>>>Note that *every* access to an element of sealed range involves a copy construction.  When sorting a sealed range of BigInts (Array!BigInt), even an innocent comparison creates two BigInt copies:
>>>
>>>    if (!less(r[i], r[p]))  // Creates two temporary copies.
>>>
>>>I think these copies can't be elided since original objects exist in a container at the same time.  Still the compared elements could be moved out and then assigned back, but that's terribly awkward.
>>>
>>>We mostly don't want to move out elements - just want to read them. Sealed ranges are inherently copy intensive, so if you will put forward the concept, copy cost of elements must be assumed to be cheap IMO.
>>>
>>>
>>>Shin
>>>
>>>Andrei Alexandrescu<andrei at erdani.com>  wrote:
>>>
>>>I am highly interested in the opinion of Phobos contributors in the
>>>>matter of copy construction (just posted the message below).
>>>>
>>>>Andrei
>>>>
>>>>-------- Original Message --------
>>>>Subject: Re: Ruling out arbitrary cost copy construction?
>>>>Date: Sat, 30 Oct 2010 22:56:24 -0500
>>>>From: Andrei Alexandrescu<SeeWebsiteForEmail at erdani.org>
>>>>Newsgroups: digitalmars.D
>>>>
>>>>On 10/30/2010 09:40 PM, Michel Fortin wrote:
>>>>
>>>>On 2010-10-30 20:49:38 -0400, Andrei Alexandrescu
>>>>><SeeWebsiteForEmail at erdani.org>  said:
>>>>>
>>>>>
>>>>>On 10/30/10 2:24 CDT, Don wrote:
>>>>>>
>>>>>>At the moment, I think it's impossible.
>>>>>>>Has anyone succesfully implemented refcounting in D? As long as bug 3516
>>>>>>>(Destructor not called on temporaries) remains open, it doesn't seem to
>>>>>>>be possible.
>>>>>>>Is that the only blocker, or are there others?
>>>>>>>
>>>>>I managed to define and use RefCounted in Phobos. File also uses hand-made reference counting. I think RefCounted is a pretty good abstraction (unless it hits the bug you mentioned.)
>>>>>
>>>>I like the idea of RefCounted as a way to automatically make things reference counted.
>>>>
>>>Unfortunately it's only a semi-automated mechanism.
>>>
>>>
>>>But like File and many similar ref-counted structs, it has this race
>>>>condition (bug 4624) when stored inside the GC heap. Currently, most of Phobos's ref-counted structs are race-free only when they reside on the stack or if your program has only one thread (because the GC doesn't spawn threads if I'm correct).
>>>>
>>>>It's a little sad that the language doesn't prevent races in destructors
>>>>(bug 4621).
>>>>
>>I hope we're able to solve these implementation issues that can be seen as independent from the decision at hand.
>>
>>Walter and I discussed the matter again today and we're on the brink of deciding that cheap copy construction is to be assumed. This simplifies the language and the library a great deal, and makes it perfectly good for 95% of the cases. For a minority of types, code would need to go through extra hoops (e.g. COW, refcounting) to be compliant.
>>
>>I'm looking for more feedback from the larger D community. This is a very important decision that marks one of the largest departures from the C++ style. Taking the wrong turn here could alienate many programmers coming from C++.
>>
>>So, everybody - this is really the time to speak up or forever be silent.
>>
>>
>>Andrei
>>
_______________________________________________
>>phobos mailing list
>>phobos at puremagic.com
>>http://lists.puremagic.com/mailman/listinfo/phobos
>>
_______________________________________________
>phobos mailing list
>phobos at puremagic.com
>http://lists.puremagic.com/mailman/listinfo/phobos
>
>



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20101101/5a081557/attachment-0001.html>
November 01, 2010
Le 2010-11-01 ? 0:21, Andrei Alexandrescu a ?crit :

> Alright, then how do we solve refcounting of constant objects (see Michel Fortin's question)? My solution involves casting away const and keeping immutability information at runtime. Is that acceptable?

I don't see a big problem in bypassing const. But const objects might be immutable, and immutable objects are implicitly shared. So for immutable objects you'll need to use atomic increment/decrement on the reference counter; is this why you want to keep track of immutability at runtime?

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



November 01, 2010
On 11/1/10 10:59 AM, Michel Fortin wrote:
> Le 2010-11-01 ? 0:21, Andrei Alexandrescu a ?crit :
>
>> Alright, then how do we solve refcounting of constant objects (see Michel Fortin's question)? My solution involves casting away const and keeping immutability information at runtime. Is that acceptable?
>
> I don't see a big problem in bypassing const. But const objects might be immutable, and immutable objects are implicitly shared. So for immutable objects you'll need to use atomic increment/decrement on the reference counter; is this why you want to keep track of immutability at runtime?

I keep immutability info during runtime to avoid trying to write to immutable data.

I'm not sure about what to do for the GC affecting the reference count. It does look like we need to use atomic refcounting, which is a major setback for the entire approach.

In brief, if we want to go with cheap copy construction, we don't currently have a solution.


Andrei
November 01, 2010
Can someone please fill me in?  Despite Michael Fortin's repeated attempts to explain it, I still don't understand how the status quo could generate a race condition under reasonable, real-world scenarios.  As I understand it (please correct whatever reasoning is wrong):

1.  Incrementing/decrementing a size_t is atomic (i.e. has no intermediate state) on x86 and probably just about any other arch.  It is not, however, guaranteed sequentially consistent unless you use the lock instruction.

2.  Stopping the world to do GC acts as an implicit fence.  If it didn't, then GC would be horribly broken.  This means that all refcount increments/decrements that happened in the owner thread should be visible to the collecting thread upon starting a collection.

3.  You'd need some kind of fence (explicit or implicit) on terminating GC anyhow, to make data structures updated by the GC thread visible to all threads, thus making any increment/decrement of the reference count field done in the GC thread visible to all threads.

On Mon, Nov 1, 2010 at 12:17 PM, Andrei Alexandrescu <andrei at erdani.com>wrote:

> On 11/1/10 10:59 AM, Michel Fortin wrote:
>
>> Le 2010-11-01 ? 0:21, Andrei Alexandrescu a ?crit :
>>
>>  Alright, then how do we solve refcounting of constant objects (see
>>> Michel Fortin's question)? My solution involves casting away const and keeping immutability information at runtime. Is that acceptable?
>>>
>>
>> I don't see a big problem in bypassing const. But const objects might be immutable, and immutable objects are implicitly shared. So for immutable objects you'll need to use atomic increment/decrement on the reference counter; is this why you want to keep track of immutability at runtime?
>>
>
> I keep immutability info during runtime to avoid trying to write to immutable data.
>
> I'm not sure about what to do for the GC affecting the reference count. It does look like we need to use atomic refcounting, which is a major setback for the entire approach.
>
> In brief, if we want to go with cheap copy construction, we don't currently have a solution.
>
>
> Andrei
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20101101/0c83caef/attachment.html>
November 01, 2010
Le 2010-11-01 ? 12:30, David Simcha a ?crit :

> Can someone please fill me in?  Despite Michael Fortin's repeated attempts to explain it, I still don't understand how the status quo could generate a race condition under reasonable, real-world scenarios.  As I understand it (please correct whatever reasoning is wrong):
> 
> 1.  Incrementing/decrementing a size_t is atomic (i.e. has no intermediate state) on x86 and probably just about any other arch.  It is not, however, guaranteed sequentially consistent unless you use the lock instruction.
> 

> 2.  Stopping the world to do GC acts as an implicit fence.  If it didn't, then GC would be horribly broken.  This means that all refcount increments/decrements that happened in the owner thread should be visible to the collecting thread upon starting a collection.
> 
> 3.  You'd need some kind of fence (explicit or implicit) on terminating GC anyhow, to make data structures updated by the GC thread visible to all threads, thus making any increment/decrement of the reference count field done in the GC thread visible to all threads.


The current GC stops other threads only during mark and sweep, it then restarts the other threads and after that it call destructors. That could be changed, but it'd stop the world for a little longer.

Is "i++" really atomic when i is a size_t? I though it was a read-modify-write operation. The read might be atomic, the write might be atomic, but the whole isn't. And in addition to atomicity, it needs to be sequentially consistent unless we change the GC to keep threads frozen while calling the destructors.

One option to avoid atomic ops would be to make the GC call destructors in the thread that owns the object, but for that you have to figure out which thread owns what and postpone destruction until that thread allocates new memory from the GC again. And this approach won't work for immutable objects anyway: they're implicitly shared.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



« First   ‹ Prev
1 2 3 4 5