problem when pthread_* functions are invoked from dynamic library

Kishore K hellokishore at gmail.com
Fri Dec 2 12:16:07 UTC 2005


hi all

I am facing some problems if pthread_self() and some other pthread_*
functions are invoked from a dynamic library.
Here is my code

/*******threadTest.c ******/
#include <stdio.h>
#include <pthread.h>

void * process(void * arg)
{
        pthread_t id;
        id = pthread_self();
        fprintf(stderr, "Pthread id in thread %s = %u\n", (char*)arg, id);
        return NULL;
}
int testFunc()
{
        int retcode;
        pthread_t th_a;
        void *retval;

        printf("Hello from testFunc\n");
        retcode = pthread_create(&th_a, NULL, process, (void *) "a");
        if (retcode != 0)
                fprintf(stderr, "create a failed %d\n", retcode);
        fprintf(stderr, "Pthread id in caller = %u\n", th_a);
        pthread_join(th_a, &retval);
        return 0;
}
Dynamic library libthreadTest.so is built, based on the above file with the
following command

$mips-linux-gcc -shared -o libthreadTest.so threadTest.c -lpthread

The function testFunc() is called from another file test.c

/**** test.c ******/
#include <stdio.h>
extern int testFunc();
int main(int argc, char* argv[])
{
        printf("Hello from main\n");
        testFunc();
        return 0;
}

Final executable is made using
$mips-linux-gcc -o test test.c -L. -lthreadTest

If this executable is run on the target

# ./test
Hello from main
Hello from testFunc
Pthread id in caller = 1026
Pthread id in thread a = 0

Here, I am getting two different values for pthread_self(), which are
invoked from two different places in threadTest.c
Anyone, has an idea, why this is happening ??

If I link libpthread.so explicitly with final executable, I don't see any
problem. The pthread_self() returns same value from both the places.

Again, if the following line is commented out
        weak_alias (__pthread_return_0, pthread_self)
from libc/misc/weaks.c in uClibc source code and built the library again, I
don't see any problem, even if libpthread.so is not explicitly
 linked with the final executable.
May I know, whether I can comment out this line from libc/misc/weaks.c. If
not, what is the purpose of this?

I am using uClibc-0.9.27 based toolchain with gcc-3.3.6 and
binutils-2.14.90.0.8 for mips platform.

thanks,
--kishore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/uclibc/attachments/20051202/8e1dc146/attachment.htm 


More information about the uClibc mailing list