* problem in running pthread application
@ 2006-10-14 6:14 Ratheesh
0 siblings, 0 replies; only message in thread
From: Ratheesh @ 2006-10-14 6:14 UTC (permalink / raw)
To: linuxppc-embedded
[-- Attachment #1: Type: text/plain, Size: 2119 bytes --]
Hello everybody,
I have a problem in running a pthread based
application whose source is given below.
//sample.c
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *thread1_function(void *);
void *thread2_function(void *);
int main(void)
{
pthread_t thread1,thread2;
char *message1 = "Thread 1";
char *message2 = "Thread 2";
int iret1,iret2;
iret1 = pthread_create(&thread1,NULL,thread1_function,(void*)message1);
iret2 = pthread_create(&thread2,NULL,thread2_function,(void*)message2);
pthread_join(thread1,iret1);
pthread_join(thread2,iret2);
printf("Thread 1 returns: %d\n",iret1);
printf("Thread 2 returns: %d\n",iret2);
exit(0);
}
void *thread1_function(void *ptr)
{
char *message;
message = (char *) ptr;
while(1)
{
printf("%s\n",message);
sleep(5);
}
}
void *thread2_function(void *ptr)
{
char *message;
message = (char *) ptr;
while(1)
{
printf("%s\n",message);
sleep(8);
}
}
//end of sample.c
I compiled using the command $powerpc-linux-uclibc-gcc -lpthread -o sample
sample.c
when I run on my target board(MPC850 based custom board), I find multiple
copies of the same program(I am invoking only once) is running. ps -e
command show the following output.
PID Uid VmSize Stat Command
1 root 392 S init
2 root SW [keventd]
3 root SWN [ksoftirqd_CPU0]
4 root SW [kswapd]
5 root SW [bdflush]
6 root SW [kupdated]
7 root SW [rpciod]
36 root 1284 S /bin/snmpd -Dagentx
41 root 1024 S /bin/bash
42 root 372 S /sbin/syslogd -n -m 0
43 root 348 S /sbin/klogd -n
51 root 296 S sample
52 root 296 S sample
53 root 296 S sample
54 root 296 S sample
56 root 372 R ps
Why is this program is running multiple copies in the memory? How to avoid
this.If I compile
the same program in PC(x86 with glibc) It is running fine(no multiple
copies). So how to avoid this what is wrong with my program? Please help me.
Regards,
Ratheesh
[-- Attachment #2: Type: text/html, Size: 3718 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-10-14 6:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-14 6:14 problem in running pthread application Ratheesh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).