comp.lang.ada
 help / color / mirror / Atom feed
From: Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject: Re: Task_Barriers
Date: Fri, 26 Jul 2019 20:10:27 -0400
Date: 2019-07-26T20:10:27-04:00	[thread overview]
Message-ID: <325njep3qliem0e01tt71lgjlicbmq5rkl@4ax.com> (raw)
In-Reply-To: f1aefde4-371a-49f5-9e7b-4e8b0bc807a2@googlegroups.com

On Fri, 26 Jul 2019 03:38:36 -0700 (PDT), Gilbert Gosseyn <hnptz@yahoo.de>
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/

      parent reply	other threads:[~2019-07-27  0:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-25 16:32 Task_Barriers Gilbert Gosseyn
2019-07-25 16:43 ` Task_Barriers Dmitry A. Kazakov
2019-07-25 18:56 ` Task_Barriers Dennis Lee Bieber
2019-07-25 20:11   ` Task_Barriers Jeffrey R. Carter
2019-07-25 20:17 ` Task_Barriers Simon Wright
2019-07-25 21:59   ` Task_Barriers Randy Brukardt
2019-07-26  7:52     ` Task_Barriers Simon Wright
2019-07-26 23:59       ` Task_Barriers Dennis Lee Bieber
2019-07-26 10:38   ` Task_Barriers Gilbert Gosseyn
2019-07-26 11:09     ` Task_Barriers Dmitry A. Kazakov
2019-07-26 15:03     ` Task_Barriers Simon Wright
2019-07-27  0:10     ` Dennis Lee Bieber [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