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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a24:e08c:: with SMTP id c134-v6mr123906ith.7.1537578582085; Fri, 21 Sep 2018 18:09:42 -0700 (PDT) X-Received: by 2002:a9d:4a3c:: with SMTP id h57-v6mr1749otf.1.1537578581928; Fri, 21 Sep 2018 18:09:41 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!209.85.166.215.MISMATCH!x188-v6no125735ite.0!news-out.google.com!z5-v6ni103ite.0!nntp.google.com!x81-v6no126699ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 21 Sep 2018 18:09:41 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=176.59.41.142; posting-account=-CxkpgoAAAC4sQudwZebWnArsZbT2lvS NNTP-Posting-Host: 176.59.41.142 References: <64f5bbad-2f06-4ea9-aa33-8c66e9cbb2a5@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Ada.Containers and concurrent modification exception. From: rakusu_klein@fastmail.jp Injection-Date: Sat, 22 Sep 2018 01:09:42 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:54400 Date: 2018-09-21T18:09:41-07:00 List-Id: =D1=81=D1=83=D0=B1=D0=B1=D0=BE=D1=82=D0=B0, 22 =D1=81=D0=B5=D0=BD=D1=82=D1= =8F=D0=B1=D1=80=D1=8F 2018 =D0=B3., 2:27:59 UTC+3 =D0=BF=D0=BE=D0=BB=D1=8C= =D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Randy Brukardt =D0=BD=D0= =B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB: > And it would be wrong: deleting a node from the Map only invalidates curs= ors=20 > that point at that node, not cursors that point at other nodes in the Map= .=20 > Those can continue to be used (for instance, if stored in another contain= er)=20 > until their nodes or the map as a whole are deleted. You missed the point, perhaps because I choose obscure names for properties= . Sorry. State_Type is a modification's counter with a wrap-around sematic. It count= s modifications of an internal container's structure and exists in all cont= ainer's instances (call them Actual_Modifications) and in every iterator's = instance (call them Known_Modifications). When an iterator is created for a= n existing container, its counter is initialized by value of that container= , so their values are equal. When container is changed by any public method= , its modification counter is incremented by one. If modification process b= y public method involves an iterator, the modification counter inside the i= terator also incremented by one. Before any modification will doing, values= of counters for container and iterator will be compared for equality, and = if The_Container.Actual_Modifications /=3D The_Cursor.Known_Modifications t= hen raise Concurent_Modification. Look at http://developer.classpath.org/doc/java/util/TreeMap-source.html = =E2=80=9CknownMod=E2=80=9D and =E2=80=9CmodCount=E2=80=9D private ints. > when a container is destroyed and a new one created in the same location It will be created with zero number of modifications. If iterator will have= zero number of modifications too, nothing wrong happens (just because cont= ainer is empty), otherwise exception will be raised. > It also could fail if the counter wrapped arround Why? We just need to check if the value of Known_Modifications in iterator = is equal to the value of Actual_Modifications in container. It is the reaso= n why I called they both a State =E2=80=94 an unique number that reflects a= number of container's modifications. And on a 32-bit machine we have a 4_2= 94_967_296 modifications before a wrap. Of course, there is a possibility of check failure exists, but it has very = low probability.