clone task will not give up processor
I am attempting to clone multiple tasks in the code below. However, when executing the first cloned task holds the processor forever. If I remove the while(1) in TaskTester, then each task is generated, but only after the previous task has completed. This is running TS-Linux or Debian Linux on an ARM. What am I doing wrong? (I added the sched_yield() but it didn't make any difference.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include "ct.h"
int TaskTester(void * dummy)
{
if(dummy != NULL)
{
while(1)
{
// do something here
write(STDERR_FILENO,"Task ",5);
write(STDERR_FILENO,(char *)dummy,1);
write(STDERR_FILENO," reporting\n",12);
sched_yield();
// sched_getscheduler();
sleep(10);
}
write(STDERR_FILENO,"Task ",5);
write(STDERR_FILENO,(char *)dummy,1);
write(STDERR_FILENO," exiting\n",12);
}
return(*((int *)dummy));
}
int main(void)
{
void *stack, *none;
char stack_mem[100];
int task_count;
pid_t pid;
char temp = 'A';
stack = (void *)&stack_mem[0];
none = (void*)&temp;
for(task_count = 0; task_count < TASK_COUNT; task_count++)
{
temp = (char)('A' + task_count);
if( (pid = clone((void*)TaskTester((void *)none), (void*)0L,0,0)) == 0)
{
write(STDERR_FILENO,"ERROR: clone failed\n",21);
exit(1);
}
else
{
write(STDERR_FILENO,"Parent task sees creation pid\n",26);
fprintf(stderr,"Parent sees child pid = %ld\n",(long)pid);
}
}
return(0);
}
|