Walter Bright wrote:
dsimcha wrote:
Ok, one thing that leads to a lot of misunderstanding and confusion is
that
there's (as far as I can tell) absolutely no documentation of what shared
does/will do or what its semantics are/will be, other than a few
newsgroup posts
from years ago,which were tentative, and the "migrating to shared"
article, which
is mostly about thread-local storage. Also, as far as I can tell,
shared is not
fully implemented yet, because core.thread doesn't require a shared
delegate. Is
this correct?
Yes.
Here are some questions, and this is just what I've been able to think
of off the
top of my head in a few minutes:
What guarantees is shared supposed to provide?
Shared means that multiple threads can access the data. The guarantee is
that if it is not shared, and not immutable, that only the current
thread can see it.
What does shared have to do with synchronization?
Only shared data can be synchronized. It makes no sense to synchronize
thread local data.
What does shared have to do with memory barriers?
Reading/writing shared data emits memory barriers to ensure sequential
consistency (not implemented).
What are the semantics of casting FROM unshared TO shared?
You'd better be sure there are no other unshared references to that same
data.
What are the semantics of casting FROM shared TO unshared?
You'd better be sure there are no other shared references to that same
data.
Why doesn't shared appear anywhere in core.thread?
Because nobody has spent the effort to do it.
Thanks Walter for doing this. These questions and their answers could
start an FAQ page on D's website.
Andrei