possible pthread_join bug in uclibc thread lib

Ashwin Tanugula ashwin.tanugula at broadcom.com
Fri Sep 15 01:07:11 UTC 2006


Hi,

I have couple to test programs which get killed on mips, but they run
fine on fedora core 3 and nptl.

Here are the codes and outputs.

test case 1

===========

#include <stdio.h>

#include <pthread.h>

#include <unistd.h>

#define THREADS_NO 10

pthread_t threads[THREADS_NO];

void *thread_function(void *arg)

{

int no = (int)arg;

printf("Thread %d calling pthread exit.\n", no);

pthread_exit(NULL);

}

int main()

{

int i;

for (i = 0; i < THREADS_NO; i++)

pthread_create(&threads[i], NULL, thread_function, (void *)i);

for (i = 0; i < THREADS_NO; i++)

{

pthread_join(threads[i], NULL);

printf("Completed join with thread %d\n",i);

}

printf("Done joining all threads.\n"); pthread_exit(NULL); }

output

=======

# threadtest2-mipsel

Thread 0 calling pthread exit.

Thread 1 calling pthread exit.

Thread 2 calling pthread exit.

Thread 3 calling pthread exit.

Thread 4 calling pthread exit.

Thread 5 calling pthread exit.

Thread 6 calling pthread exit.

Thread 7 calling pthread exit.

Completed join with thread 0

Completed join with thread 1

Completed join with thread 2

Completed join with thread 3

Completed join with thread 4

Completed join with thread 5

Completed join with thread 6

Completed join with thread 7

Killed

test case 2

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

#include <sys/time.h>

#include <signal.h>

#include <fcntl.h>

#include <sys/syscall.h>

#include <sys/mman.h>

#include <stdio.h>

#include <unistd.h>

#include <string.h> /* memset() */

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <netdb.h>

#include <sys/types.h>

#include <sched.h>

#include <pthread.h>

#define USER_BUF_SIZE 188*1024*10

typedef struct test

{

int ch;

#define OPT_START 0x00000002

/* streaming parameters */

unsigned char options;

/* internal members */

int fd; 

pthread_t producer_thread;

int sig;

pthread_mutex_t mutex;

} test_t;

test_t tests[3];

/* Main loop of the Reader Thread - the task of this function is to read
index data

from filesystem and feed it frame at a time */

void *thread_func(void *data)

{

test_t *pb = (test_t *)data;

unsigned char *index = malloc(256);

unsigned char *userbuf_org; 

pthread_attr_t attr;

struct sched_param params;

int scheduler;

char devname[256];

 

 

userbuf_org = (unsigned char *) malloc(USER_BUF_SIZE+4095);

printf("Thread %p:%p, is starting\n", pb->producer_thread, userbuf_org);

while (1)

{ 

pb->sig=1; 

if (!(pb->options & OPT_START)) {

break;

} else {

sched_yield();

continue;

}

}

printf("Thread %p:%p, is exiting\n", pb->producer_thread, userbuf_org);

out:

free(index);

free(userbuf_org);

pthread_exit(NULL); 

return NULL;

}

 

int main() {

int i;

test_t * p;

memset(tests, 0, sizeof (tests));

for (i = 0; i < 3; i++) {

p = &tests[i];

p->ch = i;

p->sig = 0; 

p->options |= OPT_START;

pthread_create(&p->producer_thread, NULL, thread_func, (void*)p);

}

getchar();

for (i = 0; i < 3; i++) {

p = &tests[i];

if(p->sig != 1)

{

fprintf(stderr, "thread %p did not set sig",p->producer_thread);

continue;

}

p->options &= ~(OPT_START);

pthread_join(p->producer_thread, NULL);

printf("currend id %d\n", i);

}

return 0;

}

test case 2 output

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

# pthread_test-mipsel

Thread 0x402:0x2abe0008, is starting

Thread 0x803:0x2adb8008, is starting

Thread 0xc04:0x2af90008, is starting

c

Thread 0x402:0x2abe0008, is exiting

currend id 0

Thread 0x803:0x2adb8008, is exiting

currend id 1

Killed

 

Has anybody had problems with pthread_join before. Is this a bug or else
can somebody give me some pointers on this.

Thanks

Ashwin

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/uclibc/attachments/20060914/ff63af4b/attachment-0001.htm 


More information about the uClibc mailing list