[comp.sys.amiga.tech] Tasking

hcobb@walt.cc.utexas.edu (Henry J. Cobb) (03/19/90)

	How I handle subtasks:

	My subtask starts out waiting at a port.  When I have somthing for it 
to do I hand it a message at that port, it goes and does its thing, replys the
message and then waits at that port.

	Any time my main program is holding the message it may safely kill the
subtask, modulo resources.

	Example: task to manage a window:

A:	The main program at some time tells the waiting task to open a window.
	(The message to the task includes some parameters for that window).  
	The task calls openwindow and replies with the result, and goes back 
	to waiting.

B:	The program decides that it wants some input, so sends the task a 
	request for input.  The task turns on the menu bar and waits for
	messages from either the IDCMP or task-control ports.

C:	If the task gets an input from the IDCMP it turns off the menu bar
	and notes the input in the task control message which it now replies
	to and waits on the ports. 

D:	Finally the program tells the task to close its window and clean up.
	With the reply in hand in now kills the task.

	Note that the main program does nothing but manage tasks.  It is almost
always free to respond instantly to new inputs, and the outstanding requests
to its subtasks tells it what it must do to shut down:

while(some_request_outstanding)
	wait(on_all_outstanding_tasks)
	for each_responding_task	
		killtask(responding_task)
	Henry J. Cobb	hcobb@ccwf.cc.utexas.edu
	"I was not here; I did not say this."