[uClibc] pthread problem

Syam Krishna Babbellapati syamkris at gmail.com
Mon Jun 13 17:34:25 UTC 2005


Hi All,

 I am currently facing a problem regarding pthreads while running on
MIPS 4Kc processor.

Environment details: uClibc version is 0.9.26, gcc-3.3.4, linux-2.4.20
kernel, processor :MIPS 4Kc with MMU.

When I run the code which is attached below, the following sequence of
operations occur.
1. Main forks - creating a child process
2. Child process - issues a pthread_create
After this, I should ideally see parent, child and the new thread
getting time slices in a round robin fashion.

But, what we see on the target is that parent and the new thread run
forever alternately and child process gets blocked (or in other words
it doesn't run at all). If we let the thread to exit, then the child
process gets a chance and runs.
 
One other interesting thing is - if we do a static compilation
(instead of using shared library) with pthread library, then the
problem disappears.

Also, the same code when run with a gcc on the x86 host works just
fine irrespective of how it is compiled with no such scheduling
problems.

The toolchain, which I am using is an in-house toolchain built using
build-root.

I am curious, if any one of you can give me any pointers. Do you think
it is a problem with some build options in uClibc?

Please let me know your views on if you have encountered


Here is the code which is bothering me.

=======================================================

#include<stdio.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

typedef struct{
int i[40];
char c[555];
}ram;

ram r2;

void *thread_func(ram *r1)
{
		char str[10];
		int i=0;

		while(1)
			printf("Inside thread\n");

		printf("Thread Exiting\n");
		pthread_exit(&i);
		return NULL;    
}


int main()
{
pthread_t threadid;
int i = 1000, iRetVal;
char str[10];

printf("Thread test program\n");

printf("\n Now calling fork\n");
i=fork();
if(i== 0)
{
printf("Now calling Pthread\n");

if((iRetVal = pthread_create(&threadid, NULL, ((void*)thread_func),&r2)) != 0) 
{
	printf("Creating STUN thread failed\n");
	return -1;
}

printf("In the child process*********************\n");

while(1)
	printf("In the child\n");
return 0;
}
printf("In the parent process*********************\n");

while(1)
	printf("In the parent \n");
return 0;            
}


================================================================



More information about the uClibc mailing list