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 10.13.219.149 with SMTP id d143mr27693597ywe.2.1458657424751; Tue, 22 Mar 2016 07:37:04 -0700 (PDT) X-Received: by 10.182.49.197 with SMTP id w5mr399587obn.16.1458657424714; Tue, 22 Mar 2016 07:37:04 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!y89no8603364qge.0!news-out.google.com!u9ni4066igk.0!nntp.google.com!nt3no3856108igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 22 Mar 2016 07:36:57 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=71.171.109.232; posting-account=vk6_JwoAAABkMyHO1YfdP69Hm3CpbdGR NNTP-Posting-Host: 71.171.109.232 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2c50ad2f-e6d5-4dc9-b4d1-905409311a97@googlegroups.com> Subject: Assignment with Adjust and Task Safety From: Jeremiah Injection-Date: Tue, 22 Mar 2016 14:37:04 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:29844 Date: 2016-03-22T07:36:57-07:00 List-Id: I've been playing around with shared/safe/smart pointer representations in = Ada and have been trying to wrap my head around how task safety works with = Adjustment. I definitely get the concept of Atomic increment/decrement in = order to allow to shared pointers in two separate task to work safely, but = when two separate tasks work on the same shared pointer, I am having troubl= e using atomic increment/decrement to prevent the following issue: Initial conditions: 1. Task_A and Task_B both have access to Shared_Pointer_A 2. Shared_Pointer_A currently is the only reference to Object_A (count =3D= 1) 3. Shared_Pointer_B currently points to a different Object_B (count =3D 1 = or whatever). Additionally, Shared_Pointer_B is only used by Task_B. 4. Shared_Ponter_C is currently null and only used by Task_A If I start an assignment in Task_A of Shared_Pointer_C :=3D Shared_Pointer_= A, but get interrupted by Task_B in between when the contents of Shared_Poi= nter_A are copied into Shared_Pointer_C and when Shared_Pointer_C is adjust= ed, if Task_B then does the assignment Shared_Pointer_A :=3D Shared_Pointer= _B, how do I prevent Shared_Pointer_C from working with a reference that is= finalized by Task_B's assignment process? An illustration: Task_A: Finalize(Shared_Pointer_C); Copy Shared_Pointer_A into Shared_Pointer_C Task_A is yielded and Task B Starts Task_B: Finalize(Shared_Pointer_A); -- uh oh?? Copy Shared_Pointer_B into Shared_Pointer_A Adjust Shared_Pointer_A do some Task_B stuff until Task_B yields and Task_A starts up Task_A: Adjust(Shared_Pointer_A); -- Contents invalid??? I don't think atomic increment/decrement will fix this as the task switch h= appens outside of both Adjust and Finalize. Is there some other way to pre= vent this? I know at the higher level I can wrap Shared_Pointer_A into a p= rotected type to ensure the assignments and reads from it are protected, bu= t that is something normally out of the scope of the Shared_Pointer_Type. I've been looking at other implementations, but haven't found how this inst= ance is protected against. It may not be outside of forcing assignment thr= ough a protected type, but wanted to check. Note that I am not accounting for the temporary objects for brevity in the = example. Additionally, this may just be bad design all around, but I am tr= ying to look at the mechanics behind this as well and if it is even possibl= e to do this safely. Thank you.