cloned tasks will not give up processor
When running this test code, the first created clone will not give up the processor. The remaining tasks are never created.
If I take the while(1) out of the TaskTester(), then each task will be created in order, but only after the previous tasks have ended. I added the sched_yield() call, but nothing changed.
This is running TS-Linux or Debian Linux on an ARM processor.
I am not interested in the tasks sharing resources. Am I using clone incorrectly?
Thanks
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#define TASK_COUNT 3
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();
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);
}
|