Multithreaded application behaves differently in different platforms

Hi all,

I have a multithreaded application which i have run in a development board and in PC. My development board is based on a PXA270 processor that runs Linux

2.6.25 kernel and my PC is x86 with linux 2.6.21 kernel.

In the application, i am creating 4 threads.I am printing the parent process ID and the self process Id in all the threads including main.

The output shows that in PC,all the threads have same SELF PID and process ID,which means the application is running as a single process.

But in my development board, the SELF PID's of the all the threads differ and parent PID of the threads and self PID of main thread are different. I have posted the code and output i have obtained below.

Code: ##### #include #include #include #include

void *thread1(void*); void *thread2(void*); void *thread3(void*); void *thread4(void*);

int main() { pthread_t tid[3]; int ret; ret=pthread_create(&tid[0],NULL,(void*)&thread1,NULL); ret=pthread_create(&tid[1],NULL,(void*)&thread2,NULL); ret=pthread_create(&tid[2],NULL,(void*)&thread3,NULL); ret=pthread_create(&tid[3],NULL,(void*)&thread4,NULL);

printf("main():Parent ID is %d.Self PID is %d\n",getppid(),getpid()); while(1) { } }

void *thread1(void* arg) { printf("Test thread 1.Parent ID is %d.Self PID is %d\n",getppid (),getpid()); while(1) { } }

void *thread2(void* arg) { printf("Test thread 2.Parent ID is %d.Self PID is %d\n",getppid (),getpid()); while(1) { } }

void *thread3(void* arg) { printf("Test thread 3.Parent ID is %d.Self PID is %d\n",getppid (),getpid()); while(1) { } }

void *thread4(void* arg) { printf("Test thread 4.Parent ID is %d.Self PID is %d\n",getppid (),getpid()); while(1) { } }

Output in Board: ############## /tmp # ./multi_thread Test thread 1.Parent ID is 995.Self PID is 996 Test thread 2.Parent ID is 995.Self PID is 997 Test thread 3.Parent ID is 995.Self PID is 998 Test thread 4.Parent ID is 995.Self PID is 999 main():Parent ID is 701.Self PID is 994

Output in PC: ########### [root@ragha my_learning]# ./multi_thread_pc main():Parent ID is 5828.Self PID is 7193 Test thread 3.Parent ID is 5828.Self PID is 7193 Test thread 2.Parent ID is 5828.Self PID is 7193 Test thread 1.Parent ID is 5828.Self PID is 7193 Test thread 4.Parent ID is 5828.Self PID is 7193

Reply to
Harry
Loading thread data ...

Hi,

Have You tried disabling all sorts of optimization by the compiler?

Yours sincerely, Rene

Reply to
Rene

Harry schrieb:

I suppose the Linux version on the Dev board does not support NPTL, and thus "Linux threads" is used by the pthreadlib.

With "Linux threads" by means of pthreadlib, each thread of an application is a process (and an additional "management" thread is created). The OS does not know that the threads belong to one another. With NPTL the OS manages the threads of an application as parts of a single process.

-Michael

Reply to
Michael Schnell

Thanks for the clarifications.

After googling, i came to know that the 'nptl' source is integrated with glibc.So i downloaded the glibc-2.9 and tried cross compiling it for my board,but it seems that the support for ARM architecture has been phased out.

Is there any other way to obtain the 'nptl' source and compile it for ARM.

Reply to
Harry

No. Why do you think so?

jbe

Reply to
Juergen Beisert

NPTL needs to be supported by the Kernel. If it isn't glibc's pthread library will fall back to Linux Threads.

-Michael

Reply to
Michael Schnell

Reply to
Harry

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.