Order of the Butterfly
Posts: 358 from 2003/10/3
From: Padova - Italy
Aloha!
Now in my self-made Amiga C programming course I've some problem with creating a Task.
This example is cut'n'pasted from Amiga RKM 2.1 (sorry, I've only this version!):
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/tasks.h>
#include <libraries/dos.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <stdlib.h>
#include <stdio.h>
#define STACK_SIZE 1000L
struct Task *task = NULL;
char *simpletaskname = "SimpleTask";
ULONG sharedvar;
void simpletask(void);
void cleanexit(UBYTE *,LONG);
int main(int argc,char **argv)
{
sharedvar = 0L;
task = CreateTask(simpletaskname,0,simpletask,STACK_SIZE);
if(!task) cleanexit("Can't create task",RETURN_FAIL);
printf("This program initialized a variable to zero, then started a\n");
printf("separate task which is incrementing that variable right now,\n");
printf("while this program waits for you to press RETURN.\n");
printf("Press RETURN now: ");
getchar();
printf("The shared variable now equals %ld\n",sharedvar);
/* We can simply remove the task we added because our simpletask does not make */
/* any system calls which could cause it to be awakened or signalled later. */
Forbid();
DeleteTask(task);
Permit();
cleanexit("",RETURN_OK);
}
void simpletask()
{
while(sharedvar < 0x8000000) sharedvar++;
/* Wait forever because main() is going to RemTask() us */
Wait(0L);
}
void cleanexit(UBYTE *s, LONG e)
{
if(*s) printf("%s\n",s);
exit(e);
}
I think the little proggy is self explanatory. It should run a task that
increases a global dummy variable and when the user hits return the main task kill
the subtask and return the value of the variable.
The problem is that MOS SDK compilation is ok but when I run the proggy
after waiting some second before pressing RETRUN i get the value of
"sharedvar" always equal 0!
It seems the subtask never starts...
Could you help me please? It's a sort of incompatibility between MOS and AOS?
And yes how can start a task in MOS? I'm not able to find an example in the
SDK...
Thanx in advance and ciao!
P.s: as I'm posting, I'd like to thanx the equipe @
GURU-MEDITATION.net for their beautiful MUI tutorial!
It's in french but I think it's very understandable
for all!!! Than U very much for your support guys!
-------------------