On 1/12/06, Yang Huang <justin8086@xxxxxxxxx> wrote:
you want these processes/threads to compete for the stdout, right ?? so you where expecting a result like some prints marked 1 then some others marked 2 ..
this must happen actually but i think 3 iterations will not be enough for a process/thread to spend it's time quantum (the CPU time devoted for it)
make each process/thread execute for a large number of iterations and you'll get what you want
hope it helps
MHD.Tayseer
Hi list,
I am currently trying to simulate a situation that two
processes/threads competing for the CPU resource. A lot of examples
and articles have metioned this issue. However, when I tried this with
"pthread_create" and "fork", neither of them works!
The platfrom is Linux 2.6.10, uClibc 3.3.5, my root file system is
built with Buildroot 1.0. The processor is VIA Eden ESP 6000.
Part of the code using fork is listed below:
childpid = fork();
if (childpid >= 0)
{
if (childpid == 0)
{
for (i=0; i<3; i++)
{
printf("mark 1!\n");
}
exit(0);
}
}
else
{
for (i=0; i<3; i++)
printf("mark 2!\n");
wait(&status);
exit(0);
}
as for pthread_create, part of the code is like this:
void thread(void)
{
for(i=0;i<3;i++)
printf("mark 2!\n");
}
int main(void)
{
ret=pthread_create(&id,NULL,(void *) thread,NULL);
for(i=0;i<3;i++)
printf("mark 1!\n");
pthread_join(id,NULL);
}
Whenever I run, both two codes give the same output:
mark 1!
mark 1!
mark 1!
mark 2!
mark 2!
mark 2!
which indicates that there is always the case that only when one
process/thread finishes can the other be given the CPU to continue. Is
that correct? How can I simulate the competition then?
you want these processes/threads to compete for the stdout, right ?? so you where expecting a result like some prints marked 1 then some others marked 2 ..
this must happen actually but i think 3 iterations will not be enough for a process/thread to spend it's time quantum (the CPU time devoted for it)
make each process/thread execute for a large number of iterations and you'll get what you want
MHD.Tayseer
Thank you in advanced for any suggestions!
regards,
Yang
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/