comp.lang.ada
 help / color / mirror / Atom feed
From: Bob Duff <bobduff@theworld.com>
Subject: Re: Q: tasks and recursion, binary tree
Date: Wed, 06 May 2015 08:27:29 -0400
Date: 2015-05-06T08:27:29-04:00	[thread overview]
Message-ID: <87r3qt99hq.fsf@theworld.com> (raw)
In-Reply-To: 4a618fc7-a443-4ce3-884f-bd40b359dcd4@googlegroups.com

gautier_niouzes@hotmail.com writes:

>     count: Natural:= 0;
>     pragma Volatile(count);
...
>         count:= count + 1;

You need an atomic increment.  Volatile doesn't do that (see the RM for
what it actually does).  Pragma Atomic doesn't do that either.
So the code has a data race, which makes it erroneous, which means
anything could happen (the program might crash, or might get wrong
answers, or might get correct answers).

You could create a protected object that encapsulates Count.
Or with GNAT you could look at System.Atomic_Counters.

- Bob


      reply	other threads:[~2015-05-06 12:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-06 11:13 Q: tasks and recursion, binary tree gautier_niouzes
2015-05-06 12:27 ` Bob Duff [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox