comp.lang.ada
 help / color / mirror / Atom feed
* Selective accept in Ada tasking
@ 2002-11-27  8:22 Ivan Paniagua
  2002-11-27  9:33 ` Peter Hermann
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Ivan Paniagua @ 2002-11-27  8:22 UTC (permalink / raw)


I'm a beginner and I have a problem. This code makes my CPU reach
100%:

task body Man_Motor1 is
begin
	while not Fin loop
		select			
			accept Subir;
			null; -- Some actions
		or
			accept Bajar;
			null; -- Some actions
		or
			accept Parar;
			null; -- Some actions
		or
			terminate;
		end select;
	end loop;
end Man_Motor1;

I'm using GNAT 3.14 in a Windows XP platform. If I introduce a delay
before de end loop all it's OK, but what I want is that the task keep
sleeping till it has a call to an entry without consuming a lot of CPU
time.

Can anybody help me?
Thank you very much.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Selective accept in Ada tasking
  2002-11-27  8:22 Ivan Paniagua
@ 2002-11-27  9:33 ` Peter Hermann
  2002-11-27 14:41 ` SteveD
  2002-11-27 16:14 ` tmoran
  2 siblings, 0 replies; 9+ messages in thread
From: Peter Hermann @ 2002-11-27  9:33 UTC (permalink / raw)


Ivan Paniagua <paniaguaivan@hotmail.com> wrote:
> I'm using GNAT 3.14 in a Windows XP platform. If I introduce a delay
> before de end loop all it's OK, but what I want is that the task keep
> sleeping till it has a call to an entry without consuming a lot of CPU
> time.

I am using GNAT3.15p windows2000 CPU600MHz.
The delay within the loop of the accepting task seems not be justified
IMHO because this task should be constantly alert and working on demand.
The consumer task on the other side defines the needs and if necessary,
the CPU then goes up to 100%, of course. If not, then not :-)
The following code shows a pretty CPU usage profile in windows task manager:

procedure paniaguaivan is

  value : float := 0.0;
  fin : boolean := false;

--From: paniaguaivan@hotmail.com (Ivan Paniagua)
--Newsgroups: comp.lang.ada
--Subject: Selective accept in Ada tasking
--Date: 27 Nov 2002 00:22:41 -0800   Wed Nov 27 09:33:53 2002
--Organization: http://groups.google.com/
--Lines: 28

--I'm a beginner and I have a problem. This code makes my CPU reach 100%:

procedure work is begin
for i in 1..1e7 loop
  value := float(i+i)+0.5;
end loop;
end work;

task Man_Motor1 is
  entry subir;
  entry bajar;
  entry parar;
end Man_Motor1;
task body Man_Motor1 is
begin
	while not Fin loop
		select			
			accept Subir; --aufstehen, go up, monter
			work;--null; -- Some actions
		or
			accept Bajar; -- come down
			null; -- Some actions
		or
			accept Parar; -- anhalten, die, stoj
			null; -- Some actions
		or
			terminate;
		end select;
	end loop;
end Man_Motor1;

--I'm using GNAT 3.14 in a Windows XP platform. If I introduce a delay
--before de end loop all it's OK, but what I want is that the task keep
--sleeping till it has a call to an entry without consuming a lot of CPU
--time.

--Can anybody help me?
--Thank you very much.
begin
  loop
    Man_Motor1.subir;
    Man_Motor1.bajar;
    Man_Motor1.parar;
    delay 3.0;
  end loop;
end paniaguaivan;

-- 
--Peter Hermann(49)0711-685-3611 fax3758 ica2ph@csv.ica.uni-stuttgart.de
--Pfaffenwaldring 27 Raum 114, D-70569 Stuttgart Uni Computeranwendungen
--http://www.csv.ica.uni-stuttgart.de/homes/ph/
--Team Ada: "C'mon people let the world begin" (Paul McCartney)



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Selective accept in Ada tasking
@ 2002-11-27 10:02 Grein, Christoph
  2002-11-27 14:17 ` Ivan
  2002-11-27 15:02 ` Adrian Knoth
  0 siblings, 2 replies; 9+ messages in thread
From: Grein, Christoph @ 2002-11-27 10:02 UTC (permalink / raw)


> I'm a beginner and I have a problem. This code makes my CPU reach
> 100%:

Looks like a bug to me. It should stop at the select and wait until there is an 
entry call. Is it possible that there is always a call present?

What happens if you remove the terminate alternative? Should not really have an 
effect, but just to see whether there is a problem in Gnat.

> 
> task body Man_Motor1 is
> begin
> 	while not Fin loop
> 		select			
> 			accept Subir;
> 			null; -- Some actions
> 		or
> 			accept Bajar;
> 			null; -- Some actions
> 		or
> 			accept Parar;
> 			null; -- Some actions
> 		or
> 			terminate;
> 		end select;
> 	end loop;
> end Man_Motor1;
> 
> I'm using GNAT 3.14 in a Windows XP platform. If I introduce a delay
> before de end loop all it's OK, but what I want is that the task keep
> sleeping till it has a call to an entry without consuming a lot of CPU
> time.
> 
> Can anybody help me?
> Thank you very much.
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Selective accept in Ada tasking
  2002-11-27 10:02 Selective accept in Ada tasking Grein, Christoph
@ 2002-11-27 14:17 ` Ivan
  2002-11-27 14:56   ` Preben Randhol
  2002-11-27 15:02 ` Adrian Knoth
  1 sibling, 1 reply; 9+ messages in thread
From: Ivan @ 2002-11-27 14:17 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1511 bytes --]

    I have found some resources concerning this, like
http://www.cs.utsa.edu/~danlo/ada/ada95.htm that recomend a delay 0.0. It's
not a serious solution but it runs. Maybe another compiler instead of GNAT
takes a better solution?

    Thanx.



"Grein, Christoph" <christoph.grein@eurocopter.com> escribi� en el mensaje
news:mailman.1038391741.12325.comp.lang.ada@ada.eu.org...
> > I'm a beginner and I have a problem. This code makes my CPU reach
> > 100%:
>
> Looks like a bug to me. It should stop at the select and wait until there
is an
> entry call. Is it possible that there is always a call present?
>
> What happens if you remove the terminate alternative? Should not really
have an
> effect, but just to see whether there is a problem in Gnat.
>
> >
> > task body Man_Motor1 is
> > begin
> > while not Fin loop
> > select
> > accept Subir;
> > null; -- Some actions
> > or
> > accept Bajar;
> > null; -- Some actions
> > or
> > accept Parar;
> > null; -- Some actions
> > or
> > terminate;
> > end select;
> > end loop;
> > end Man_Motor1;
> >
> > I'm using GNAT 3.14 in a Windows XP platform. If I introduce a delay
> > before de end loop all it's OK, but what I want is that the task keep
> > sleeping till it has a call to an entry without consuming a lot of CPU
> > time.
> >
> > Can anybody help me?
> > Thank you very much.
> > _______________________________________________
> > comp.lang.ada mailing list
> > comp.lang.ada@ada.eu.org
> > http://ada.eu.org/mailman/listinfo/comp.lang.ada





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Selective accept in Ada tasking
  2002-11-27  8:22 Ivan Paniagua
  2002-11-27  9:33 ` Peter Hermann
@ 2002-11-27 14:41 ` SteveD
  2002-11-27 16:14 ` tmoran
  2 siblings, 0 replies; 9+ messages in thread
From: SteveD @ 2002-11-27 14:41 UTC (permalink / raw)


Please provide a complete sample program that illustrates the problem and is
ready to compile.  I tested your sample after adding a dozen lines of code
to turn it into a program that compiles it ran flawlessly on W2k compiled
with Gnat 3.15p.

SteveD

"Ivan Paniagua" <paniaguaivan@hotmail.com> wrote in message
news:c560b18f.0211270022.72569d49@posting.google.com...
> I'm a beginner and I have a problem. This code makes my CPU reach
> 100%:
>
> task body Man_Motor1 is
> begin
> while not Fin loop
> select
> accept Subir;
> null; -- Some actions
> or
> accept Bajar;
> null; -- Some actions
> or
> accept Parar;
> null; -- Some actions
> or
> terminate;
> end select;
> end loop;
> end Man_Motor1;
>
> I'm using GNAT 3.14 in a Windows XP platform. If I introduce a delay
> before de end loop all it's OK, but what I want is that the task keep
> sleeping till it has a call to an entry without consuming a lot of CPU
> time.
>
> Can anybody help me?
> Thank you very much.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Selective accept in Ada tasking
  2002-11-27 14:17 ` Ivan
@ 2002-11-27 14:56   ` Preben Randhol
  0 siblings, 0 replies; 9+ messages in thread
From: Preben Randhol @ 2002-11-27 14:56 UTC (permalink / raw)


Ivan wrote:
> I have found some resources concerning this, like
> http://www.cs.utsa.edu/~danlo/ada/ada95.htm that recomend a delay
> 0.0. It's not a serious solution but it runs. Maybe another
> compiler instead of GNAT takes a better solution?

I thought that one should put in a 0.01 delay (or less) so that there is
a bit time to switch the tasks ?

At least I experience that the CPU goes to 100% if I don't do it, but if
I do it my program doesn't make a blip on the CPU usage screen.

-- 
Preben Randhol ------------------------ http://www.pvv.org/~randhol/ --
                          �1984 is soon coming to a computer near you.�



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Selective accept in Ada tasking
  2002-11-27 10:02 Selective accept in Ada tasking Grein, Christoph
  2002-11-27 14:17 ` Ivan
@ 2002-11-27 15:02 ` Adrian Knoth
  1 sibling, 0 replies; 9+ messages in thread
From: Adrian Knoth @ 2002-11-27 15:02 UTC (permalink / raw)


Grein, Christoph <christoph.grein@eurocopter.com> wrote:

>> I'm a beginner and I have a problem. This code makes my CPU reach
>> 100%:
> Looks like a bug to me. 

I think so, too. Same code works fine under Linux.


-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

Error in operator: add beer



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Selective accept in Ada tasking
  2002-11-27  8:22 Ivan Paniagua
  2002-11-27  9:33 ` Peter Hermann
  2002-11-27 14:41 ` SteveD
@ 2002-11-27 16:14 ` tmoran
  2002-11-29  7:02   ` Ivan
  2 siblings, 1 reply; 9+ messages in thread
From: tmoran @ 2002-11-27 16:14 UTC (permalink / raw)


> task body Man_Motor1 is
  Are you sure it's that task body that's using 100%?  Is the rest of
the program waiting on a big delay or what?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Selective accept in Ada tasking
  2002-11-27 16:14 ` tmoran
@ 2002-11-29  7:02   ` Ivan
  0 siblings, 0 replies; 9+ messages in thread
From: Ivan @ 2002-11-29  7:02 UTC (permalink / raw)



I have analyze all my code and make some tests and I was confused. The
problem with the CPU wasn't in the selective accept. It seems to be OK. We
can have a task with a infinte loop and a selective accept with the "or
terminate" clause without making our CPU burn ;-).

Thank you for your time and sorry.





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2002-11-29  7:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-27 10:02 Selective accept in Ada tasking Grein, Christoph
2002-11-27 14:17 ` Ivan
2002-11-27 14:56   ` Preben Randhol
2002-11-27 15:02 ` Adrian Knoth
  -- strict thread matches above, loose matches on Subject: below --
2002-11-27  8:22 Ivan Paniagua
2002-11-27  9:33 ` Peter Hermann
2002-11-27 14:41 ` SteveD
2002-11-27 16:14 ` tmoran
2002-11-29  7:02   ` Ivan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox