valid uses of shared
Steven Schveighoffer
schveiguy at yahoo.com
Mon Jun 11 03:24:24 PDT 2012
On Fri, 08 Jun 2012 22:01:41 -0400, mta`chrono
<chrono at mta-international.net> wrote:
> Would this be legal?
>
> class A
> {
> private static shared int counter; // shared across all instances
>
> this()
> {
> auto i = ++counter;
> pragma(msg, typeof(i)); // prints int
> }
> }
>
Yes, but it would not automatically make ++counter atomic.
My proposal is simply to avoid sharing data that shouldn't be shared (i.e.
stack data and temporaries), not to make all operations thread-safe.
-Steve
More information about the Digitalmars-d
mailing list