 |
|
| Linux Forum Index » Linux Embedded » Multithreaded application behaves differently in... |
|
Page 1 of 1 |
|
| Author |
Message |
| Harry... |
Posted: Thu Sep 10, 2009 2:49 am |
|
|
|
Guest
|
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 <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
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 at (no spam) 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 |
|
|
| Back to top |
|
|
|
| Rene... |
Posted: Thu Sep 10, 2009 3:25 pm |
|
|
|
Guest
|
Harry wrote:
Quote: 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 <pthread.h
#include <stdio.h
#include <stdlib.h
#include <unistd.h
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 at (no spam) 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
Hi,
Have You tried disabling all sorts of optimization by the compiler?
Yours sincerely,
Rene |
|
|
| Back to top |
|
|
|
| Michael Schnell... |
Posted: Thu Sep 10, 2009 3:39 pm |
|
|
|
Guest
|
Harry schrieb:
Quote:
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 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 |
|
|
| Back to top |
|
|
|
| Harry... |
Posted: Mon Sep 14, 2009 7:02 pm |
|
|
|
Guest
|
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.
On Sep 11, 2:39 am, Michael Schnell
<mschnell_at_bschnell_dot... at (no spam) aol.com> wrote:
Quote: Harry schrieb:
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 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 |
|
|
| Back to top |
|
|
|
| Juergen Beisert... |
Posted: Tue Sep 15, 2009 7:40 am |
|
|
|
Guest
|
Harry wrote:
Quote: 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.
No. Why do you think so?
jbe |
|
|
| Back to top |
|
|
|
| Michael Schnell... |
Posted: Tue Sep 15, 2009 10:49 am |
|
|
|
Guest
|
Harry wrote:
Quote: i came to know that the 'nptl' source is integrated
with glibc
NPTL needs to be supported by the Kernel. If it isn't glibc's pthread
library will fall back to Linux Threads.
-Michael |
|
|
| Back to top |
|
|
|
| Harry... |
Posted: Tue Oct 06, 2009 1:19 am |
|
|
|
Guest
|
I have been using the ELDK version 3.3 provided by denx for arm
(XSCALE).
This tool chain doesn't have support for NPTL. In their latest
toolchain version 4.4,they have support for NPTL.
After compiling the kernel and application using the 4.4 compiler,i am
able to see only one process running.
On Sep 15, 9:49 pm, Michael Schnell
<mschnell_at_bschnell_dot... at (no spam) aol.com> wrote:
Quote: Harry wrote:
i came to know that the 'nptl' source is integrated
with glibc
NPTL needs to be supported by the Kernel. If it isn't glibc's pthread
library will fall back to Linux Threads.
-Michael |
|
|
| Back to top |
|
|
|
|
|
All times are GMT - 5 Hours
The time now is Thu Nov 26, 2009 1:36 pm
|
|