Re: issue with cr_pthread.c:71 cri_pthread_init: Unable to ensure pthread_atfork() will run.

From: Paul H. Hargrove (PHHargrove_at_lbl_dot_gov)
Date: Tue Oct 21 2008 - 12:02:36 PDT

  • Next message: wchao_at_ncsu_dot_edu: "Re: issue with cr_pthread.c:71 cri_pthread_init: Unable to ensure pthread_atfork() will run."
    I regret that I can't provide much in the way of support for 0.4.x (and 
    a snapshot version at that!).
    I would guess you must have a reason for using such an old version, but 
    I would encourage you to try something newer.
    
    If you can't move to something newer, you may find the attached patch 
    useful.  It is an attempt to back-port the current version of the code 
    that issues the error message you are seeing.
    
    -Paul
    
    
    wchao_at_ncsu_dot_edu wrote:
    > Hi,
    >
    > I'm trying to run the benchmark of irs-1.4 on an x86-64 machine with the
    > kernel of 2.6.16.
    >
    > For some reason, I used the following versions for LAM/MPI and BLCR:
    > blcr-0.4.pre3_snapshot_2006_11_09
    > lam-7.2b1r10399
    >
    > I successfully built irs, however, it failed to run with the following error:
    >
    > cr_pthread.c:71 cri_pthread_init: Unable to ensure pthread_atfork() will run.
    > If you dlopen(libcr.so) or use some versions of the libraries/loaders,
    > then you may need to link libpthread explicitly (or use LD_PRELOAD).
    >
    > Then, I tried to use -lpthread (or -Wl,-rpath-link=/usr/lib64) to fix this
    > bug, but it still doesn't work. I read through Bug #460 at
    > http://upc-bugs.lbl.gov/bugzilla/show_bug.cgi?id=460, but I couldn't
    > figure out the solution.
    >
    > Would you please give me some suggestions? Any comments are welcome!
    > Thanks a lot!
    >
    > Best regards,
    > Chao
    >   
    
    
    -- 
    Paul H. Hargrove                          PHHargrove_at_lbl_dot_gov
    Future Technologies Group                 
    HPC Research Department                   Tel: +1-510-495-2352
    Lawrence Berkeley National Laboratory     Fax: +1-510-486-6900
    
    
    Index: configure.ac
    ===================================================================
    RCS file: /var/local/cvs/lbnl_cr/configure.ac,v
    retrieving revision 1.185.2.2
    diff -u -r1.185.2.2 configure.ac
    --- configure.ac	9 Nov 2006 18:21:04 -0000	1.185.2.2
    +++ configure.ac	21 Oct 2008 19:03:26 -0000
    @@ -382,6 +382,9 @@
       [AC_CACHE_SAVE
        AC_MSG_ERROR([[required library libpthread not found.]])])
     
    +# Check for atfork handling
    +AC_CHECK_FUNCS([__register_atfork])
    +
     # Probe libc for the RT signal number to use
     CR_CHECK_SIGNUM
     
    Index: libcr/cr_async.c
    ===================================================================
    RCS file: /var/local/cvs/lbnl_cr/libcr/cr_async.c,v
    retrieving revision 1.51
    diff -u -r1.51 cr_async.c
    --- libcr/cr_async.c	1 Sep 2005 03:16:04 -0000	1.51
    +++ libcr/cr_async.c	21 Oct 2008 19:03:26 -0000
    @@ -179,9 +179,9 @@
     	if (thread_state == CRI_THREAD_STOPPED) {
     	    int rc;
     
    -	    rc = pthread_atfork(NULL, NULL, &thread_reset);
    +	    rc = cri_atfork(NULL, NULL, &thread_reset);
     	    if (rc != 0) {
    -		CRI_ABORT("pthread_atfork() returned %d", rc);
    +		CRI_ABORT("cri_atfork() returned %d", rc);
     	    }
     
     	    rc = pthread_create(&my_thread, NULL, &thread_main, NULL);
    Index: libcr/cr_private.h
    ===================================================================
    RCS file: /var/local/cvs/lbnl_cr/libcr/cr_private.h,v
    retrieving revision 1.83
    diff -u -r1.83 cr_private.h
    --- libcr/cr_private.h	15 Jun 2006 19:27:36 -0000	1.83
    +++ libcr/cr_private.h	21 Oct 2008 19:03:26 -0000
    @@ -99,6 +99,11 @@
     
     // Perform pthreads-related initialization if needed.
     extern void cri_pthread_init(void);
    +#if PIC && HAVE___REGISTER_ATFORK
    +  extern int cri_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void));
    +#else
    +  #define cri_atfork pthread_atfork
    +#endif
     
     // Register a callback
     extern cr_callback_id_t cri_do_register(cri_info_t*, cr_callback_t, void*, int);
    Index: libcr/cr_pthread.c
    ===================================================================
    RCS file: /var/local/cvs/lbnl_cr/libcr/cr_pthread.c,v
    retrieving revision 1.28
    diff -u -r1.28 cr_pthread.c
    --- libcr/cr_pthread.c	24 Oct 2006 00:58:40 -0000	1.28
    +++ libcr/cr_pthread.c	21 Oct 2008 19:03:26 -0000
    @@ -30,6 +30,23 @@
     #include <errno.h>
     #include "cr_private.h"
     
    +#if PIC && HAVE___REGISTER_ATFORK
    +// pthread_atfork() handling for shared objects
    +// glibc has started putting pthread_atfork() in libpthread_nonshared.a, which is causing
    +// problems when we call from a shared library.  The problem is that the code in the
    +// static lib gets pulled into libcr.so, but its was not PIC-compiled.
    +// Therefore, we use our own private re-implementation.
    +// This implementation is closely based on glibc-2.3.2-20030313/nptl/pthread_atfork.c
    +extern void *__dso_handle __attribute__((__weak__));
    +extern int __register_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void), void *dso_handle);
    +extern int
    +cri_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
    +{ 
    +  void *my_handle = &__dso_handle ? __dso_handle : NULL;
    +  return __register_atfork(prepare, parent, child, my_handle);
    +}
    +#endif
    +
     // Holds thread-specific data key for cri_info
     pthread_key_t cri_info_key;
     
    @@ -42,6 +59,7 @@
         cri_info_free(cri_info_location());
     }
     
    +#if !HAVE___REGISTER_ATFORK
     // Interpose on fork() to ensure the pthreads version is called
     // if the caller linked us, but not the pthreads library.
     pid_t cri_fork(void)
    @@ -49,6 +67,7 @@
       return __fork();
     }
     weak_alias(cri_fork,fork);
    +#endif
     
     //
     // Initialize pthread-dependent parts
    @@ -58,6 +77,7 @@
     {
         int rc;
     
    +  #if !HAVE___REGISTER_ATFORK
         // See bug #460
         {
     	// dlopen will fail if this is a static exectuable.
    @@ -73,11 +93,12 @@
     	    dlclose(handle);
     	}
         }
    +  #endif /* !HAVE___REGISTER_ATFORK */
     
    -    // Install a pthread_atfork callback to cleanup state in children
    -    rc = pthread_atfork(NULL, NULL, &child_reset);
    +    // Install a atfork callback to cleanup state in children
    +    rc = cri_atfork(NULL, NULL, &child_reset);
         if (rc != 0) {
    -	CRI_ABORT("pthread_atfork() returned %d", rc);
    +	CRI_ABORT("cri_atfork() returned %d", rc);
         }
     
         // Setup the thread-specific data for cri_info
    

  • Next message: wchao_at_ncsu_dot_edu: "Re: issue with cr_pthread.c:71 cri_pthread_init: Unable to ensure pthread_atfork() will run."