From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Bob Duff Newsgroups: comp.lang.ada Subject: Re: Q: tasks and recursion, binary tree Date: Wed, 06 May 2015 08:27:29 -0400 Organization: A noiseless patient Spider Message-ID: <87r3qt99hq.fsf@theworld.com> References: <4a618fc7-a443-4ce3-884f-bd40b359dcd4@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="7f9625a25a27c388fa03238a79b59e0a"; logging-data="22166"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OX963ZJpINM+1JVjgeAmZ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:gde1rR3iB7LpbkaJ+f87Mzv41nA= sha1:QbxxSjF7ek5k3vlqB8ggOh8s/cA= Xref: news.eternal-september.org comp.lang.ada:25738 Date: 2015-05-06T08:27:29-04:00 List-Id: 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