comp.lang.ada
 help / color / mirror / Atom feed
* assigning priority to task
@ 2014-09-24  1:50 Stribor40
  2014-09-24  3:31 ` Jeffrey Carter
  2014-09-24 11:17 ` AdaMagica
  0 siblings, 2 replies; 12+ messages in thread
From: Stribor40 @ 2014-09-24  1:50 UTC (permalink / raw)


I am playing with example from here..
http://www.infres.enst.fr/~pautet/Ada95/e_c26_p2.ada

and each run i get different output which is ok but what I am trying to do is somehow control running of each of those 3 tasks by assigning priority to each task by using pragma PRIORITY(some int) where higher the int higher the priority.
So my question is this ....If i assign first task priority(8) and second priority(4) and third priority(2) does that mean that first task will always run first second second and third third? How does OS time slicing fit into this when priority is assigned to each task?

Thanks


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

* Re: assigning priority to task
  2014-09-24  1:50 assigning priority to task Stribor40
@ 2014-09-24  3:31 ` Jeffrey Carter
  2014-09-24  3:36   ` Stribor40
  2014-09-24  3:39   ` Stribor40
  2014-09-24 11:17 ` AdaMagica
  1 sibling, 2 replies; 12+ messages in thread
From: Jeffrey Carter @ 2014-09-24  3:31 UTC (permalink / raw)


On 09/23/2014 06:50 PM, Stribor40 wrote:
> I am playing with example from here..
> http://www.infres.enst.fr/~pautet/Ada95/e_c26_p2.ada
> 
> and each run i get different output which is ok but what I am trying to do is somehow control running of each of those 3 tasks by assigning priority to each task by using pragma PRIORITY(some int) where higher the int higher the priority.
> So my question is this ....If i assign first task priority(8) and second priority(4) and third priority(2) does that mean that first task will always run first second second and third third? How does OS time slicing fit into this when priority is assigned to each task?

Suppose you run the program on a system with 4 cores. Will the priorities
control the order in which the tasks run?

-- 
Jeff Carter
"All citizens will be required to change their underwear
every half hour. Underwear will be worn on the outside,
so we can check."
Bananas
29


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

* Re: assigning priority to task
  2014-09-24  3:31 ` Jeffrey Carter
@ 2014-09-24  3:36   ` Stribor40
  2014-09-24  5:28     ` Jeffrey Carter
  2014-09-24  3:39   ` Stribor40
  1 sibling, 1 reply; 12+ messages in thread
From: Stribor40 @ 2014-09-24  3:36 UTC (permalink / raw)


I am not sure. I would think it wouldnt matter since each task can run on one core


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

* Re: assigning priority to task
  2014-09-24  3:31 ` Jeffrey Carter
  2014-09-24  3:36   ` Stribor40
@ 2014-09-24  3:39   ` Stribor40
  2014-09-24  5:32     ` Jeffrey Carter
  2014-09-24 16:01     ` Anh Vo
  1 sibling, 2 replies; 12+ messages in thread
From: Stribor40 @ 2014-09-24  3:39 UTC (permalink / raw)


Also my box has 2 cores. Is there way in ada to see which core is running which task?


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

* Re: assigning priority to task
  2014-09-24  3:36   ` Stribor40
@ 2014-09-24  5:28     ` Jeffrey Carter
  2014-09-24 10:09       ` Stribor40
  0 siblings, 1 reply; 12+ messages in thread
From: Jeffrey Carter @ 2014-09-24  5:28 UTC (permalink / raw)


On 09/23/2014 08:36 PM, Stribor40 wrote:
> I am not sure. I would think it wouldnt matter since each task can run on one core

Probably right. That is the abstraction that Ada tasking is supposed to
represent. Trying to control when such tasks execute without having them
interact is futile.

-- 
Jeff Carter
"All citizens will be required to change their underwear
every half hour. Underwear will be worn on the outside,
so we can check."
Bananas
29


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

* Re: assigning priority to task
  2014-09-24  3:39   ` Stribor40
@ 2014-09-24  5:32     ` Jeffrey Carter
  2014-09-24 16:01     ` Anh Vo
  1 sibling, 0 replies; 12+ messages in thread
From: Jeffrey Carter @ 2014-09-24  5:32 UTC (permalink / raw)


On 09/23/2014 08:39 PM, Stribor40 wrote:
> Also my box has 2 cores. Is there way in ada to see which core is running which task?

On many modern processors, each core can execute 2 tasks at the same time
(effectively). So it may be possible for all 4 tasks in your example to run at
the same time.

An Ada-12 compiler that implements Annex D has pkg
System.Multiprocessors.Dispatching_Domains (ARM D.16.1) that lets you determine
the CPU that a task is running on, as well as aspect CPU to force a task to run
on a specific CPU. Compilers for earlier versions of Ada may have
vendor-specific ways to do similar things.

-- 
Jeff Carter
"All citizens will be required to change their underwear
every half hour. Underwear will be worn on the outside,
so we can check."
Bananas
29


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

* Re: assigning priority to task
  2014-09-24  5:28     ` Jeffrey Carter
@ 2014-09-24 10:09       ` Stribor40
  2014-09-24 19:36         ` Simon Wright
  0 siblings, 1 reply; 12+ messages in thread
From: Stribor40 @ 2014-09-24 10:09 UTC (permalink / raw)


I know but i wanted to try to see if i sssign priorities output can be somewhat controled but apparently those assigned priorities didnt matter


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

* Re: assigning priority to task
  2014-09-24  1:50 assigning priority to task Stribor40
  2014-09-24  3:31 ` Jeffrey Carter
@ 2014-09-24 11:17 ` AdaMagica
  2014-09-24 13:17   ` Stribor40
  1 sibling, 1 reply; 12+ messages in thread
From: AdaMagica @ 2014-09-24 11:17 UTC (permalink / raw)


Basically, priorities have only effect on tasks contending for the processor.

Ada 83 RM says someting like: If two tasks are runnable at the same time on a processor, it cannot be the case that the lower priority task executes while the higher one does not... Priorities should only be used for fine-tuning.

Since then, this basic rule has not changed, but has been modified by the presence of multiprocessors.

So be careful.


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

* Re: assigning priority to task
  2014-09-24 11:17 ` AdaMagica
@ 2014-09-24 13:17   ` Stribor40
  2014-09-24 14:55     ` Björn Lundin
  0 siblings, 1 reply; 12+ messages in thread
From: Stribor40 @ 2014-09-24 13:17 UTC (permalink / raw)


how is calling another task at the entry point different from main thread calling another function or procedure and passing parameters to those? sorry if question is dumb but I am just failing to see the difference....
Is it because of tasks synchronization mechanism that calling tasks waits if another tasks is using things defined after accept statement?


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

* Re: assigning priority to task
  2014-09-24 13:17   ` Stribor40
@ 2014-09-24 14:55     ` Björn Lundin
  0 siblings, 0 replies; 12+ messages in thread
From: Björn Lundin @ 2014-09-24 14:55 UTC (permalink / raw)


On 2014-09-24 15:17, Stribor40 wrote:
> how is calling another task at the entry point different from main thread calling another function or procedure and passing parameters to those? sorry if question is dumb but I am just failing to see the difference....
> Is it because of tasks synchronization mechanism that calling tasks waits if another tasks is using things defined after accept statement?
> 

(Not compiled code)

task T is
  entry T1;
  entry T2;
end T


task body T is
begin

  loop
    select
      accept T1 do
        Put_Line ("rendez-vouz start");
        Put_Line ("Do_stuff that holds caller");
        Put_Line ("rendez-vouz stop");
      done
    or
      accept T1 do
        Put_Line ("rendez-vouz start");
        Put_Line ("rendez-vouz stop");
      done
      -- parallel execution from here
      Put_Line ("Do_stuff that DOES NOT hold caller");
      -- to here
    or
      terminate;
    end select;
  end loop;
end T



if main calls T.T1, the difference
compared with calling a procedure
T1 in package T is that the work is
performed in another thread and main waits until complete.
You do not get parallel execution.
You serialize work, but could use a protected object instead

however,

if main calls T.T2, the difference
compared with calling a procedure
T2 in package T is that the work is
performed in another thread and main is released right away,
so the T2 work is carried out while main continues.
You get _parallel_ execution.



--
Björn


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

* Re: assigning priority to task
  2014-09-24  3:39   ` Stribor40
  2014-09-24  5:32     ` Jeffrey Carter
@ 2014-09-24 16:01     ` Anh Vo
  1 sibling, 0 replies; 12+ messages in thread
From: Anh Vo @ 2014-09-24 16:01 UTC (permalink / raw)


On Tuesday, September 23, 2014 8:39:20 PM UTC-7, Stribor40 wrote:
> Also my box has 2 cores. Is there way in ada to see which core is running which task?

Yes, there is. In addition, a given task can be assigned to run on specific core (CPU)

Anh Vo


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

* Re: assigning priority to task
  2014-09-24 10:09       ` Stribor40
@ 2014-09-24 19:36         ` Simon Wright
  0 siblings, 0 replies; 12+ messages in thread
From: Simon Wright @ 2014-09-24 19:36 UTC (permalink / raw)


Stribor40 <ikamzic@gmail.com> writes:

> I know but i wanted to try to see if i sssign priorities output can be
> somewhat controled but apparently those assigned priorities didnt
> matter

It used to be the case on Linux (and, I think, Solaris) that pragma
Priority only had any effect if the program was running as root:

   $ sudo ./task1

I just tried this on Mac OS X and running as root made no difference.


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

end of thread, other threads:[~2014-09-24 19:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-24  1:50 assigning priority to task Stribor40
2014-09-24  3:31 ` Jeffrey Carter
2014-09-24  3:36   ` Stribor40
2014-09-24  5:28     ` Jeffrey Carter
2014-09-24 10:09       ` Stribor40
2014-09-24 19:36         ` Simon Wright
2014-09-24  3:39   ` Stribor40
2014-09-24  5:32     ` Jeffrey Carter
2014-09-24 16:01     ` Anh Vo
2014-09-24 11:17 ` AdaMagica
2014-09-24 13:17   ` Stribor40
2014-09-24 14:55     ` Björn Lundin

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