The "no gc" crowd

Jonathan M Davis jmdavisProg at gmx.com
Thu Oct 10 16:33:08 PDT 2013


On Thursday, October 10, 2013 11:11:12 Sean Kelly wrote:
> On Oct 10, 2013, at 10:55 AM, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> wrote:
> > On 10/10/13 12:33 AM, Jonathan M Davis wrote:
> >> Far more frequently, you want to share a type which you would also
> >> use normally as a thread-local variable, and that means casting.
> > 
> > no
> 
> Yeah, I'd want to see this claim backed up by some examples. The only data
> I share globally in my own apps is the occasional container. Configuration
> data, a user database, whatever. I'll also frequently move data between
> threads while dispatching tasks, but otherwise everything is thread-local. 
> I imagine there are other reasonable methods for using shared data, but I
> don't know what they are.

Yeah, but it's that moving data between threads while dispatching tasks which 
requires casting. Pretty much anything which isn't a value type has to be cast 
to either immutable or shared in order to pass it across threads, and then it 
needs to then be cast back to thread-local mutable on the other side for to be 
useable. Unless you're only passing really basic stuff like int, or the types 
that your passing are only used for being passed across threads (and thus are 
designed to work as shared), you end up having to cast.

The fact that you can only pass shared or immutable objects across combined 
with the fact that shared objects are generally unusable makes it so that 
you're at minimum going to have to either cast the object once it gets to the 
other thread, even if it was constructed as shared. And since shared is so 
useless means that if you need to do anything more than simply construct the 
object before passing it across, you're going have to have it as thread-local 
in the originating thread as well.

I just don't see how you could avoid casting when passing ownership of an 
object from one thread to another without having a way to pass an object 
across threads without having to make it shared or immutable to pass it.

- Jonathan M Davis


More information about the Digitalmars-d mailing list