[comp.sys.amiga.tech] Did anything evercome of "Spawning Tasks that Draw"?

dillon@CORY.BERKELEY.EDU (Matt Dillon) (03/15/88)

>    Anyway, I am about to spawn some tasks that draw and would appreciate a
>summary now if anything ever came of that topic.  It would be even better if
>someone with some experiance with this could send me Email, and let me ask a
>series of questions.
>...
>    What I'm not clear on is how to make my drawing task go to sleep after
>making a call to the Blitter, and then wake up when the call is done.
>...
>    Also, If anyone could give info on the overhead of task spawning/switching
>I'd appreciate it.

	You can use a TASK for anything that doesn't use DOS (dos.library).
If all you are using is Intuition and the graphics.library, a task is fine.
If the task is physically part of the parent's segment (i.e. access to
the parent's global variables), you can share library base pointers fine.
Remember that the task is, well, a task, which means it has its own signal
set and can only Wait() on ports it owns.

	So, what I suggest is something like this:

	-Spawn a child TASK via CreateTask() with a priority HIGHER than
	 that of the parent.  Have the child TASK create a private message
	 port that the parent can PutMsg() a message with your list of
	 graphics commands.

	-Have some sort of initial handshake with the parent (easy to
	 do with signals) so the parent doesn't start sending commands
	 before the child has setup the private message port.

	-The child TASK simply WaitPort()'s on this port (this is how it
	 waits for things), then gets the message, executes the operation 
	 list, does a ReplyMsg(), then returns back to the WaitPort().

	NOTE:  Obviously blitter operations involve some waiting (for the
	blitter to finish), thus even though the child task is of higher
	priority, it will not stop the parent dead.  You *want* the child
	at a higher priority to get maximum graphics throughput... so 
	when the blitter is done with an operation, the child can stuff
	another operation into it.

	-Some kind of shutdown handshake sequence when you are done and
	 want to quit.  Hint: It is perfectly legal to RemTask(NULL) while
	 in Forbid() state, so the child ack-die sequence can look like:

		(child task):

		Forbid();
		Signal(Parent, ImDeadSignal)
		RemTask(NULL);	/* kill myself */

	 The parent will not get the signal until the child has actually
	 killed itself.

						-Matt