comp.lang.ada
 help / color / mirror / Atom feed
* Re: tasks, simple question
  1999-11-15  0:00 tasks, simple question G
  1999-11-15  0:00 ` Ehud Lamm
  1999-11-15  0:00 ` DuckE
@ 1999-11-15  0:00 ` tmoran
  1999-11-15  0:00 ` Matthew Heaney
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: tmoran @ 1999-11-15  0:00 UTC (permalink / raw)


>What I am wondering is where and when one would use them.
  That is not a "simple question".

  Tasks, like subroutines, help you separate a big, complicated,
problem into a set of small, simple ones.  Usually an application
will divide rather clearly into a collection of fairly independent
activities.  If those activities occur sequentially, you use a
series of subroutine calls.  If some of those activities naturally
need to, or can, occur simultaneously, then tasks might be
appropriate.  If you have multiple CPUs, then your program will
complete faster if you can put different tasks on different CPUs
and thus overlap the time they take.

  Say you have a program that accepts a number from the user, then
calculates away for 10 seconds, displays an answer, and then waits
for the next input.  You are asked to convert that to a program
that does the same for each of 10 different users.  You could write
something that switches back and forth between scanning the 10
input lines for requests, calculating answers for anyone who has
submitted a complete request, and sending results.  It's probably a
lot easier to simply convert your procedure to a task type, then
declare multiple tasks of that type, one per input line, and let
them all run.

  Suppose you need to save away the audio and video from a TV
program onto your hard disk for later playback.  Suppose further
that you get one field of video every 1/60 second, and one buffer
load of audio every 20 ms (1/50 second).  You could write a program
that processes on a 1/300 second cycle, handling 1/5 of a video
field and 1/6 of a sound buffer each time.  Now make the problem
nastier by allowing the end user to vary the sound quality, which
means a fixed size buffer fills up in different lengths of time.
It might be much simpler to run two tasks, one for video and one
for audio, each with the cycle time it finds most convenient.

  Suppose there are several different algorithms you can use to
solve a certain type of problem, with different algorithms taking
very different lengths of time depending on the particular data.
One possible approach is to start up one task for each algorithm,
and the first one to finish tells the others to quit.  If you have
a multiple CPU machine, and one algorithm(task) per CPU, that's an
obvious way to get the answer as quickly as possible.  Even if you
had to share a single CPU, if the running times of different
algorithms are extremely different (and unpredictable), this
approach might still be better than the "put all your eggs in one
basket" approach of running algorithm A until it succeeds or you
give up, then try with algorithm B, etc.

  Task interactions usually take significantly longer than simple
procedure calls, and you can do nasty things with tasks getting in
each other's way, but they can be a powerful way to structure, or
even to speed up, an application.




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

* Re: tasks, simple question
  1999-11-15  0:00 tasks, simple question G
                   ` (2 preceding siblings ...)
  1999-11-15  0:00 ` tmoran
@ 1999-11-15  0:00 ` Matthew Heaney
  1999-11-16  0:00 ` tmoran
  1999-11-18  0:00 ` Riyaz Mansoor
  5 siblings, 0 replies; 8+ messages in thread
From: Matthew Heaney @ 1999-11-15  0:00 UTC (permalink / raw)


In article <382FC705.29121528@interact.net.au> , G 
<Dizzy@interact.net.au>  wrote:

> What I am wondering is where and when one would use them.
>
> What sort of role they play, so to say.  What sort of things one
> would use them for.

Tasks are used for implementing concurrent abstractions.


package Philosophers is

  type Philosopher_Type (Id : Positive) is limited private;

  <ops for philosophers>

private

  -- This handles the concurrency aspects of a philosopher
  -- abstraction.
  type Philosopher_Task_Type
    (Philosopher : access Philosopher_Type);

  type Philosopher_Type (Id : Positive) is
    limited record

      <other components, probably including a protected object>

      Philosopher_Task :
        Philosopher_Task_Type (Philosopher_Type'Access);

    end record;

end Philosophers;


Here, we have a group of philosophers who all eat and think
simultaneously.  An abstraction that is concurrent will have a component
implemented as a task.




--
If we let the Creationists have their way, we may as well go whole hog.
Let us reintroduce the flat-earth theory, the chemistry of the four
elements, and mediaeval astrology.  For these outworn doctrines have
just as much claim to rival current scientific views as Creationism does
to challenge evolutionary biology.

Abusing Science: The Case Against Creationism
Philip Kitcher




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

* Re: tasks, simple question
  1999-11-15  0:00 tasks, simple question G
  1999-11-15  0:00 ` Ehud Lamm
@ 1999-11-15  0:00 ` DuckE
  1999-11-15  0:00 ` tmoran
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: DuckE @ 1999-11-15  0:00 UTC (permalink / raw)


The simplest example I can think of is printing.

If you're in a word processor and select "print", without tasking you might
be forced for the printout to complete before continuing your work.  With
tasking you can continue working while your document prints.

If you're document is printing while you continue editing, what happens to
that part of the document you're editing?  Will it show the most recent
changes?  Or will it print the last copy of the document you saved?  This is
an example of concurrency concerns, that is the things you must be concerned
with when operations are being performed on the same data by multiple tasks.

I hope this helps,
SteveD

G <Dizzy@interact.net.au> wrote in message
news:382FC705.29121528@interact.net.au...
> I think I have a basic understanding of what is going on with tasks.
>
> What I am wondering is where and when one would use them.
>
> What sort of role they play, so to say.  What sort of things one
> would use them for.
>
> Or are such things not at all defined and down to personal pref. ?
> I wonder because if someone can tell me the sort of places these things
> are used, then
> I may understand them better.
>
> :-)
> -G
>






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

* tasks, simple question
@ 1999-11-15  0:00 G
  1999-11-15  0:00 ` Ehud Lamm
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: G @ 1999-11-15  0:00 UTC (permalink / raw)


I think I have a basic understanding of what is going on with tasks.

What I am wondering is where and when one would use them.

What sort of role they play, so to say.  What sort of things one
would use them for.

Or are such things not at all defined and down to personal pref. ?
I wonder because if someone can tell me the sort of places these things
are used, then
I may understand them better.

:-)
-G





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

* Re: tasks, simple question
  1999-11-15  0:00 tasks, simple question G
@ 1999-11-15  0:00 ` Ehud Lamm
  1999-11-15  0:00 ` DuckE
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Ehud Lamm @ 1999-11-15  0:00 UTC (permalink / raw)


On Mon, 15 Nov 1999, G wrote:

|What sort of role they play, so to say.  What sort of things one
|would use them for.
|

In a sense this is like asking where procedures are used. It is hard to
give a concise and complete answer.

One issue that is sometimes overlooked, but which I find very important
(in general, not just in Ada), is that tasking is one of the abstraction
mechanisms.
So types of software elements are easier to dsrcribe using multi-tasking
concepts. The ease ,  of course, depends of the specific tasking
primitives.

The usuall example I give, and which was debunked a bit on
comp.lang.functional awhile back, is of a simulation system with all kinds
of animals:
"Consider an ecological simulation system. The
system will simulate harbivores and carnivores, wonderring on a fixed
MxN grass field. The grass grows at a certain rate - so that a certain
time after a grass spot is eaten, new grass grows to fill that
spot. When a carnivore meets a harbivore, the carnvore is the only one
to walk away. Harbivores eat grass when hungry."[1]


Tasks can help you with modelling.

They also have, naturally, technical uses, from interrupt handlers to a
mapping of OS threads - but these issues I am sure will be described by
others.

[1] This is from something temporarily titled "The Little Abstractionist;
a Cacophony of Abstraction In Ada" which I am currently writing. It is an
example based tour of various kinds of software abstractions in Ada. Not
too advanced - it start with rationals, but I am trying to make it not too
dull either. 
Is such a thing publishable?I am pretty sure that the answer is no. But
anyway I have to finish writing it first...

Ehud Lamm mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <== My home on the web 
Check it out and subscribe to the E-List- for interesting essays and more!








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

* Re: tasks, simple question
  1999-11-15  0:00 tasks, simple question G
                   ` (3 preceding siblings ...)
  1999-11-15  0:00 ` Matthew Heaney
@ 1999-11-16  0:00 ` tmoran
  1999-11-16  0:00   ` Ted Dennison
  1999-11-18  0:00 ` Riyaz Mansoor
  5 siblings, 1 reply; 8+ messages in thread
From: tmoran @ 1999-11-16  0:00 UTC (permalink / raw)


For some fairly simple examples of multiple tasks in a program,
there are links at www.adapower.com for the Dining Philosophers
(more than one version) and my multi-tasking version of "99 Bottles
of Beer on the Wall".




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

* Re: tasks, simple question
  1999-11-16  0:00 ` tmoran
@ 1999-11-16  0:00   ` Ted Dennison
  0 siblings, 0 replies; 8+ messages in thread
From: Ted Dennison @ 1999-11-16  0:00 UTC (permalink / raw)


In article <Ls5Y3.16137$dp.467369@typhoon-sf.snfc21.pbi.net>,
  tmoran@bix.com wrote:
> (more than one version) and my multi-tasking version of "99 Bottles
> of Beer on the Wall".

I guess I shouldn't ask what you were doing when you thought of that
one. :-)

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: tasks, simple question
  1999-11-15  0:00 tasks, simple question G
                   ` (4 preceding siblings ...)
  1999-11-16  0:00 ` tmoran
@ 1999-11-18  0:00 ` Riyaz Mansoor
  5 siblings, 0 replies; 8+ messages in thread
From: Riyaz Mansoor @ 1999-11-18  0:00 UTC (permalink / raw)



here are two easy examples where tasking helps (i'm sure everybody would
have come across these)

1) background spell checker
2) background printing

----------------------------------------------------

AND THEN THEIR WAS LIGHT






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

end of thread, other threads:[~1999-11-18  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-15  0:00 tasks, simple question G
1999-11-15  0:00 ` Ehud Lamm
1999-11-15  0:00 ` DuckE
1999-11-15  0:00 ` tmoran
1999-11-15  0:00 ` Matthew Heaney
1999-11-16  0:00 ` tmoran
1999-11-16  0:00   ` Ted Dennison
1999-11-18  0:00 ` Riyaz Mansoor

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