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!feeder.eternal-september.org!news.linkpendium.com!news.linkpendium.com!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 26 Jul 2019 19:10:26 -0500 From: Dennis Lee Bieber Newsgroups: comp.lang.ada Subject: Re: Task_Barriers Date: Fri, 26 Jul 2019 20:10:27 -0400 Organization: IISS Elusive Unicorn Message-ID: <325njep3qliem0e01tt71lgjlicbmq5rkl@4ax.com> References: User-Agent: ForteAgent/8.00.32.1272 X-No-Archive: YES MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-Z5U+f+QHkza0AYdoq2TXwjmrqC86yZPbRKE+C1QKp5KTBipkmekremD/QxjFjXWGsEv/iwkiYaPU2CC!7yw7x3wsAeo88qtuEd+QabFHp7dg5/APE1YBGxKqq1IbiFF92vXfjTNHDa7DyTSBOmZbshMd X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4116 Xref: reader01.eternal-september.org comp.lang.ada:56964 Date: 2019-07-26T20:10:27-04:00 List-Id: On Fri, 26 Jul 2019 03:38:36 -0700 (PDT), Gilbert Gosseyn declaimed the following: >On Thursday, July 25, 2019 at 10:17:47 PM UTC+2, Simon Wright wrote: >> >> > although it should stop when reaching an internal count number >> >> What internal count number is that? > >1 with Ada . Text IO , Ada . Synchronous_Barriers ; >2 use Ada . Text IO , Ada . Synchronous_Barriers ; >4 procedure Task_Barriers is >5 NT: constant :=2; >6 SB: Ada.Synchronous_Barriers.Synchronous_Barrier (NT) ; >7 Notified : Boolean:= False ; >8 task T1 ; >9 task T2 ; >10 >11 X: I n t e g e r :=0; >12 Y: I n t e g e r :=1; >13 >14 task body T1 is >15 begin >16 loop >17 delay 1.0 ; >18 Wait_For_Release (SB, Notified ) ; >19 X:=X+1; >20 end loop ; >21 end T1 ; >22 >23 task body T2 i s >24 begin >25 loop >26 delay 1.0 ; >27 Wait_For_Release (SB, Notified ) ; >28 Y:=Y+1; >29 end loop ; >30 end T2 ; >31 begin >32 nul l ; >33 end Task_Ba r r i e r s ; > >In this Task Barriers, procedure Task_Barriers is the parent of task T1 and task >T2. There are two synchronization channels about between two tasks. Line 18 is >sending a message that is meaning the number of blocked tasks associated with the Line 18 doesn't send anything... It invokes a method on the barrier object -- the barrier object increments its internal count of how many tasks are waiting (and blocks the calling task if the count is less than the threshold). >Synchronous Barrier object is equal to the threshold, to the line 28 that is receiving >this message and the statement is starting to execute. Here, the threshold is set to >2. In the same way, Line 27 is labeled with sending the message that the blocked >tasks are released, while Line 19 is receiving it and starting to execute. > Same -- line 27 is invoking the barrier method which causes an increment in the count of waiting tasks. When the count reaches the threshold the barrier releases ALL waiting tasks to continue, and the counter is reset to 0. There is nothing in the code that determines what order the two tasks invoke the barrier wait method. Similarly, there is nothing making use of the (randomly) set "notified" -- all that is known is that one of the two tasks will receive "True" and the other will receive "False"... but ALL tasks were released, none are waiting. {I suspect the simplest runtime is to set notified True for the task that actually triggered the threshold and leave all the other released tasks with a False} Both tasks will loop, and invoke the wait call again. The first one to do so will be blocked (counter incremented to 1), the second will increment the counter to 2, the barrier will unblock all tasks and set the counter to 0... Repeat for 68 years... -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/