This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libgomp/43697] New: Assumption about pthread_key_create leading to fatal error


File: team.c
Function: gomp_free_thread
Line number: 214
statement: struct gomp_thread *thr = gomp_thread ();

The function gomp_free_thread is registered as destructor function of
gomp_tls_key in the case of absence of TLS support by the compiler.

The problem is in gomp_thread(), and even later in gomp_free_thread you
supposed that the specific value of gomp_tls_key is still valuable but a POSIX
system (libpthread conform implementation) set this value to NULL before
calling the destructor function, so at any moment a call to
pthread_getspecific(gomp_tls_key) reached from the destructor of this key and
then using the returned value as a pointer will lead to a fatal error. At the
end of this bug-repport, you can find an extract of pthread_key_create
specification that mention this behavior.

My proposal of solution consist of re-affecting the old value which passed from
the system to the destructor, then continue of the actual code, and at end of
function, put a call to pthread_key_delete.

Here you the result of the command diff team.c team-new.c
214,215c214,223
<   struct gomp_thread *thr = gomp_thread ();
<   struct gomp_thread_pool *pool = thr->thread_pool;
---
>   struct gomp_thread *thr;
>   struct gomp_thread_pool *pool;
> 
> #ifndef HAVE_TLS
>   pthread_setspecific(gomp_tls_key, arg);
> #endif
> 
>   th = gomp_thread ();
>   pool = thr->thread_pool;
> 
246a255,258
> 
> #ifndef HAVE_TLS
>   pthread_key_delete(gomp_tls_key);
> #endif

Extract of pthread_key_create:
       An optional destructor function may be associated with each key  value.
       At  thread  exit, if a key value has a non-NULL destructor pointer, and
       the thread has a non-NULL value associated with that key, the value  of
       the key is set to NULL, and then the function pointed to is called with
       the previously associated value as its  sole  argument.  The  order  of
       destructor  calls is unspecified if more than one destructor exists for
       a thread when it exits.

Reference:
https://computing.llnl.gov/tutorials/pthreads/man/pthread_key_create.txt


-- 
           Summary: Assumption about pthread_key_create leading to fatal
                    error
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: libgomp
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ghassan dot almaless at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43697


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]