Monday, June 27, 2011

Thread Scheduling : QNX and Linux

After long time and after my first ONSITE experience, i am able to update my blog. I was thinking to do some experiments with QNX to understand or to see the behavioral difference from Linux. But i couldnt do. Now, i am starting with a small one which is not concluded.

One day, when i was reading about pthreads, simply, i have pasted the sample program in linux and run the program and i could see some expected output. But when i run the same program on QNX, i saw the difference..!!!

When i cross compiled and run the program, which creates 5 threads and each thread prints its thread number when it gets the CPU on QNX target, i was getting the same output always. Then immediately i have thought to put that into my blog. Still i couldt get the specific and particlar reason or answer for the behavior of QNX but one thing we can think about the thread library or thread schduing of QNX.

The program is :.


#include
#include
#define NUM_THREADS 5

void *PrintHello(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0; t printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
pthread_exit(NULL);
}


The output of the desktop linux is:

[pramod@testing pramod]$ ./a.out
In main: creating thread 0
In main: creating thread 1
In main: creating thread 2
In main: creating thread 3
In main: creating thread 4
Hello World! It's me, thread #3!
Hello World! It's me, thread #4!
Hello World! It's me, thread #0!
Hello World! It's me, thread #1!
Hello World! It's me, thread #2!


The output of the QNX is:

[/] ./pthread_qnx
In main: creating thread 0
Hello World! It's me, thread #0!
In main: creating thread 1
Hello World! It's me, thread #1!
In main: creating thread 2
Hello World! It's me, thread #2!
In main: creating thread 3
Hello World! It's me, thread #3!
In main: creating thread 4
Hello World! It's me, thread #4!

As its output says, this is related to thread scheduling algorithms and mechanisms.

I have put this juft for our information. To conculde on this, many people inputs are required. Please drop your comments on this or drop me a mail about your thoughts on this.

No comments:

Post a Comment