[dmd-concurrency] Smoke test
Sean Kelly
sean at invisibleduck.org
Fri Jan 8 00:18:12 PST 2010
On Jan 7, 2010, at 5:28 PM, Walter Bright wrote:
>
> Having a per-thread gc is an optimization, not a fundamental feature of the concurrency model. For one thing, it precludes casting data to immutable. For another, it may result in excessive memory consumption as one thread may have a lot of unused data in its pool that is not available for allocation by another thread.
I agree completely that having a per-thread GC is simply an optimization. I just brought it up because it's the simplest way I've come up with to think about what "shared" means. Put another way, I think of shared as controlling the access control pool the data lives in, and the lifetime of that data. If I see "T v1" then I should be able to infer that v1 is only visible to the current thread and will go away when the thread terminates. Similarly, if I see "shared T v2" I should be able to infer that v2 is globally visible and may remain until process termination.
I feel like I'm not explaining myself very well, but that's the best I can do at the moment. As a related issue, I have a feeling that the following is a bad idea, but I haven't come up with a good explanation for why yet, maybe simply the principle of least surprise?:
class C
{
shared int x;
}
auto c = new C;
sendRefToAnotherThread( c ); // fails, c is local
sendToAnotherThread( &c.x ); // succeeds, c.x is shared
More information about the dmd-concurrency
mailing list