Something needs to happen with shared, and soon.

Jonathan M Davis jmdavisProg at gmx.com
Sun Nov 11 17:03:14 PST 2012


On Monday, November 12, 2012 01:17:06 deadalnix wrote:
> Le 11/11/2012 23:36, Graham St Jack a écrit :
> > On Sun, 11 Nov 2012 22:19:08 +0100, martin wrote:
> >> On Sunday, 11 November 2012 at 20:08:25 UTC, Benjamin Thaut wrote:
> >>> Fully agree.
> >> 
> >> +1
> > 
> > +1.
> > 
> > I find it so broken that I have to avoid using it in all but the most
> > trivial situations.
> 
> That isn't a bad thing in itself.

I don' think that it's really intended that shared by 100% easy to use. You're 
_supposed_ to use it sparingly. But at this point, it borders on being utterly 
unusable.

We have a bit of a problem with the basic idea though in that you're not 
supposed to be using shared much, and it's supposed to be segregated such that 
having the shared equivalent of const (as in it works with both shared and 
non-shared) would pose a big problem (it's also probably untenable with memory 
barriers and the like), but if you _don't_ have something like that, you 
either can't use shared with much of anything, or you have to cast it away all 
over the place, which loses all of the memory barriers or whatnot. We have 
conflicting requirements which aren't being managed very well.

I don't know how protected shared really needs to be though. Anything 
involving shared should make heavy use of mutexes and synchronized and whatnot 
meaning that at least some of the protections that people want with shared are 
useless unless you're writing code which is being stupid and not using mutexes 
or whatnot. So, casting away shared might not actually be that big a deal so 
long as it's temporary to call a function (as opposed to stashing the variable 
away somewhere) and that call is protected by a mutex or other thread-
protection mechanism.

At the moment, I think that the only way to make stuff work with both shared 
and unshared (aside from using lots of casts) is to make use of templates, and 
since most of druntime and Phobos isn't tested with shared, things like Unqual 
probably screw with that pretty thoroughly. It's at least conceivable though 
that stuff like std.algorithm could work with shared just fine.

I don't think that there's much question though that shared is the major chink 
in our armor with regards to thread-local by default. The basic idea is great, 
but the details still need some work.

- Jonathan M Davis


More information about the Digitalmars-d mailing list