summaryrefslogtreecommitdiffstats
path: root/openmp/runtime/src/z_Linux_util.c
diff options
context:
space:
mode:
authorJonathan Peyton <jonathan.l.peyton@intel.com>2016-04-18 21:33:01 +0000
committerJonathan Peyton <jonathan.l.peyton@intel.com>2016-04-18 21:33:01 +0000
commitf252010f691d7ebf896ee6465c91f454fc46e621 (patch)
treec11dfc0b297f621f72afdcf68c4104e3e6a2f43d /openmp/runtime/src/z_Linux_util.c
parentf5b25f83e30af7c141af98f14dd9471c75b3aca8 (diff)
downloadbcm5719-llvm-f252010f691d7ebf896ee6465c91f454fc46e621.tar.gz
bcm5719-llvm-f252010f691d7ebf896ee6465c91f454fc46e621.zip
Fix for pthread_setspecific (TLS and shutdown) problem
Some codes that use TLS fail intermittently because one thread tries to write TLS values after the TLS key has been destroyed by another thread. This happens when one thread executes library shutdown (and destroys TLS keys), while another thread starts to execute the TLS key destructor routine. Before this change, the kmp_init_runtime flag was checked before calling pthread_* TLS functions, but this flag is set to FALSE later than the destruction of the TLS keys, which leads to failure. The fix is to check kmp_init_gtid instead, as this flag is unset *before* the destruction of TLS keys. Differential Revision: http://reviews.llvm.org/D19022 llvm-svn: 266674
Diffstat (limited to 'openmp/runtime/src/z_Linux_util.c')
-rw-r--r--openmp/runtime/src/z_Linux_util.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/openmp/runtime/src/z_Linux_util.c b/openmp/runtime/src/z_Linux_util.c
index 16fc1c9ce98..1e7683d2402 100644
--- a/openmp/runtime/src/z_Linux_util.c
+++ b/openmp/runtime/src/z_Linux_util.c
@@ -1897,18 +1897,21 @@ __kmp_yield( int cond )
void
__kmp_gtid_set_specific( int gtid )
{
- int status;
- KMP_ASSERT( __kmp_init_runtime );
- status = pthread_setspecific( __kmp_gtid_threadprivate_key, (void*)(intptr_t)(gtid+1) );
- KMP_CHECK_SYSFAIL( "pthread_setspecific", status );
+ if( __kmp_init_gtid ) {
+ int status;
+ status = pthread_setspecific( __kmp_gtid_threadprivate_key, (void*)(intptr_t)(gtid+1) );
+ KMP_CHECK_SYSFAIL( "pthread_setspecific", status );
+ } else {
+ KA_TRACE( 50, ("__kmp_gtid_set_specific: runtime shutdown, returning\n" ) );
+ }
}
int
__kmp_gtid_get_specific()
{
int gtid;
- if ( !__kmp_init_runtime ) {
- KA_TRACE( 50, ("__kmp_get_specific: runtime shutdown, returning KMP_GTID_SHUTDOWN\n" ) );
+ if ( !__kmp_init_gtid ) {
+ KA_TRACE( 50, ("__kmp_gtid_get_specific: runtime shutdown, returning KMP_GTID_SHUTDOWN\n" ) );
return KMP_GTID_SHUTDOWN;
}
gtid = (int)(size_t)pthread_getspecific( __kmp_gtid_threadprivate_key );
OpenPOWER on IntegriCloud