Amiga Features

Feature I - Multitasking

---Seperator---



Programming details - Tasks

The easiest way to create a task is using the amiga.lib CreateProcess() function. The prototype of this function is:
struct Task *CreateTask ( STRPTR name , LONG pri, funcEntry initPC, ULONG stackSize );
The function returns either a task in the Task structure, or 0 if it fails. The first argument is the name of the task to create. It should be unique and have a trailing \0. An example would be "ExampleName\0". The second argument is the task's priority. For most tasks, '0' will suffice. The third is the function entry point, which is to be your new task. This function should have a prototype form of 'void name ( void )'. The last argument is the stacksize, it should be at least 4000 bytes, but your task might need more!
Example call:
task = CreateTask ( "ExampleName\0", 0L, name, 4000L );
The next thing to know is how to stop your task. To stop your task, you either call 'DeleteTask ( 0L )' from the task itself or call 'DeleteTask ( task )' from your main program. Notice that stopping a task is only safe if it is not doing anything at the moment you stop it. You also have to free any allocated memory yourself..

Programming details - Processes

Creating a process is similar in many ways to creating tasks, so we'll jump straight in the fray with the CreateNewProcTags() function..
process = CreateNewProcTags(ULONG, ... );
As this functions uses taglists, it is easy to use. A call to CreateNewProcTags() with 'NP_Entry, funcEntry' as tags is enough to create a new process. The full example would be 'CreateNewProcTags( NP_Entry, name )'. Where name is the name of your function. Functions for a process have a different form: 'int name ( void )', so keep that in mind when creating a process.
All the information contained here and more, plus example source code is available in the lha file that was created to accompany this feature. You can download it below. Note, if you're reading this HTML after you downloaded the program from Aminet or PPArchive, the LHA-file will not be linked correctly.

CheckDownload the extra's now.

---Seperator---

Updated: 16/01/2000
E-mail us at jeroen@infothuis.nl !
Bring me back to Amiga Features, please.
Bring me back to the Power Programs homepage, please.
(C) 2000, Jeroen Knoester.