Something needs to happen with shared, and soon.
Jonathan M Davis
jmdavisProg at gmx.com
Wed Nov 14 18:51:13 PST 2012
On Wednesday, November 14, 2012 18:30:56 Andrei Alexandrescu wrote:
> On 11/11/12 6:30 PM, Walter Bright wrote:
> > 1. ensure single threaded access by aquiring a mutex
> > 2. cast away shared
> > 3. operate on the data
> > 4. cast back to shared
> > 5. release the mutex
>
> This is very different from how I view we should do things (and how we
> actually agreed to do things and how I wrote in TDPL).
>
> I can't believe I need to restart this on a cold cache.
Well, this is clearly how things work now, and if you want to use shared with
much of anything, it's how things generally have to work, because almost
nothing takes shared. Templated stuff will at least some of the time (though
it's often untested for it and probably will get screwed by Unqual in quite a
few cases), but there's no way aside from templates or casting to get shared
variables to share the same functions as non-shared ones, leading to code
duplication.
>From what I recall of what TDPL says, this doesn't really contradict it. It's
just that TDPL doesn't really say much about the fact that almost nothing will
work with shared, which means that casting is necessary.
I have no idea what we want to do about this situation though. Regardless of
what we do with memory barriers and the like, it has no impact on whether
casts are required. And I think that introducing the shared equivalent of
const would be a huge mistake, because then most code would end up being
written using that attribute, meaning that all code essentially has to be
treated as shared from the standpoint of compiler optimizations. It would
almost be the same as making everything shared by default again. So, as far as
I can see, casting is what we're forced to do.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list