Opened 14 years ago
Last modified 14 years ago
#3628 closed defect
race condition in static variable bTLSKeySetup Cpl_multiproc.cpp — at Version 1
Reported by: | lucafibbi | Owned by: | ilucena |
---|---|---|---|
Priority: | normal | Milestone: | 1.8.0 |
Component: | default | Version: | unspecified |
Severity: | normal | Keywords: | thread safe |
Cc: | warmerdam |
Description (last modified by )
In the Cpl_multiproc.cpp file when using the static variable bTLSKeySetup simultaneously from multiple threads race condition occurs.
I think that the following implementation of the functions CPLCleanupTLS and CPLGetTLSList for pthred library should be thread safe: {{ static pthread_once_t oTLSKeySetup = PTHREAD_ONCE_INIT;
static void CPLMake_key() {
if( pthread_key_create( &oTLSKey,
(void (*)(void*)) CPLCleanupTLSList ) != 0 )
{
CPLError( CE_Fatal, CPLE_AppDefined,
"pthread_key_create() failed!" );
}
}
// /* CPLCleanupTLS() */ //
void CPLCleanupTLS()
{
void papTLSList;
papTLSList = (void ) pthread_getspecific( oTLSKey ); if( papTLSList == NULL )
return;
pthread_setspecific( oTLSKey, NULL );
CPLCleanupTLSList( papTLSList );
}
// /* CPLGetTLSList() */ //
static void CPLGetTLSList()
{
void papTLSList;
if ( pthread_once(&oTLSKeySetup, CPLMake_key) != 0 ) {
CPLError( CE_Fatal, CPLE_AppDefined,
"pthread_once() failed!" );
}
papTLSList = (void ) pthread_getspecific( oTLSKey ); if( papTLSList == NULL ) {
papTLSList = (void ) CPLCalloc(sizeof(void*),CTLS_MAX*2); if( pthread_setspecific( oTLSKey, papTLSList ) != 0 ) {
CPLError( CE_Fatal, CPLE_AppDefined,
"pthread_setspecific() failed!" );
}
}
return papTLSList;
} }}}
Change History (1)
comment:1 by , 14 years ago
Cc: | added |
---|---|
Description: | modified (diff) |
Milestone: | 1.8.0 |
Owner: | changed from | to
Ivan,
Could you review and if appropriate apply the changes?