Shared and race conditions
Steven Schveighoffer
schveiguy at yahoo.com
Mon Dec 4 14:08:28 UTC 2017
On 12/4/17 4:09 AM, Kagamin wrote:
> On Wednesday, 29 November 2017 at 16:13:13 UTC, Wanderer wrote:
>> static void getId(shared IdGen!(MyId)* g)
>> {
>> writeln("next: ", g.next());
>> writeln("next: ", g.next());
>> }
>
> writeln synchronizes on stdout, so your code is mostly serialized, good
> example of a very subtle race condition.
Well, this is just why you don't see output items that are mixed lines
(i.e. "nenext: 1\nxt: 2\n" instead of "next: 1\nnext: 2\n")
The next calls are not synchronized.
-Steve
More information about the Digitalmars-d-learn
mailing list