[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pthread_create hangs when both app & shlib linked against -lpthread

From: Erland Lewin
Subject: pthread_create hangs when both app & shlib linked against -lpthread
Date: Mon, 29 Apr 2002 12:15:46 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9+) Gecko/20020415

I have a bug related to linking and pthreads under glibc-2.2.2 and Linux (2.4.19-pre56). gcc version 3.0.2, gcc thread model: posix.

I create a shared library, which I link against -lpthread. I then create an application which I link against both the shared library and -lpthread. When the application calls pthread_create, it will hang because the thread manager thread segfaults. I havn't managed to debug why the thread manager thread segfaults, gdb doesn't seem to want to step into the thread manager init function.

If I remember correctly, one should link with the shared libraries at all times to make sure the symbol-versioning works correctly, right?

Find attached a minimal case. When you run testapp.c it will freeze. If testapp.c isn't linked agains libpthread, it will not hang.

Please cc: replies to me directly with any comments or advice, since I don't subscribe to bug-glibc.

I'm sending this mail to those who seem to be maintaining linuxthreads, forgive me if I sent it too indiscriminately.

 Thanks for any help!

   Erland Lewin

LOADLIBES = -lpthread

all: libtestlib.so testapp

libtestlib.so: testlib.o
        $(LD) -shared testlib.o -lpthread -o libtestlib.so

testapp: testapp.o libtestlib.so
        $(CC) -L. testapp.o -lpthread -ltestlib -o testapp
 * testapp
 * To test behaviour with linking of pthread

#include <assert.h>
#include <stdio.h>
#include <pthread.h>
#include "testlib.h"

static void *threadFunc( void *args );

int main( int argc, char **argv )
  int err;
  pthread_t thread;
  fprintf( stderr, "initializing testlib.\n" );
  fprintf( stderr, "testlib initialized, creating thread.\n" );
  err = pthread_create( &thread, NULL, threadFunc, NULL );
  assert( err == 0 );
  fprintf( stderr, "thread created, joining...\n" );
  pthread_join( thread, NULL );
  fprintf( stderr, "thread joined, finished.\n" );
  return 0;

static void *threadFunc( void *args )
  return args;


void testlib_init();

 * Test library

void testlib_init()

reply via email to

[Prev in Thread] Current Thread [Next in Thread]