Concurrency.

Jonathan M Davis jmdavisProg at gmx.com
Mon Nov 28 10:59:40 PST 2011


On Monday, November 28, 2011 18:41:46 Debdatta wrote:
> >>There is one to one feature correspondence.
> 
> Of course. That is obvious.:D It just seemed counter intuitive to have every
> variable I declare to be thread local. Will experiment with it some more
> and see if I can get used to the concept. You seem to have very good
> reasons to prefer it, and I hope I can see them too. :D

It's only counter-intuitive because most languages share everything by 
default. Well-written multi-threaded code already separates everything such 
that threads communicate only at key points in the program, so while it's 
atypical to make much thread-local in other languages, good programs in other 
lanuages generally wouldn't care if most of their variables became thread-
local. D just takes it to the next level by actually making them thread-local 
and enforcing it with the type system. So now, each of those points where 
threads are supposed to communicate either use message passing or shared, and 
the rest of the program is protected from having its pieces stomp on each 
other unless you go out of your way to make it happen.

Ultimately, D's basic approach makes more sense IMHO, but it's just not what 
has typically been done in other languages, so it requires mental shift, but 
since most good programs essentially already follow D's model in other 
languages (just without usually actually making the data thread-local), 
ultimately, it's not really all that big a shift.

I've had to deal with programs where any thread can be anywhere in the code, 
and it's horrific. D's allows such an approach, but it makes it a lot harder, 
so the default approach ends up being much more sane.

- Jonathan M Davis


More information about the Digitalmars-d mailing list