c++ - Why do I get a segmentation fault when adding ltalloc with MinGW -


i tried build application ltalloc. tried mingw32 4.9.1 , mingw64-32 4.9.2. compiles , links fine when run segmentation fault occurs. debugging pinpointed problem following code:

#include <pthread.h> #pragma weak pthread_once #pragma weak pthread_key_create #pragma weak pthread_setspecific static pthread_key_t pthread_key; static pthread_once_t init_once = pthread_once_init; static void init_pthread_key() { pthread_key_create(&pthread_key, release_thread_cache); } static thread_local int thread_initialized = 0; static void init_pthread_destructor()//must called when block placed thread cache's free list {     if (unlikely(!thread_initialized))     {         thread_initialized = 1;         if (pthread_once)         {             pthread_once(&init_once, init_pthread_key);  // <--- causes segsegv             pthread_setspecific(pthread_key, (void*)1);//set nonzero value force calling of release_thread_cache() on thread terminate         }     } } 

as far know both versions support thread-local storage natively. wiki of of ltalloc wrote following:

warning: in builds of mingw there problem emutls , order of execution of thread destructor (all thread local variables destructed before it), , termination of thread lead application crash.

unfortunately warning doesn't tell me anything. googling didn't make me smarter.

out of blue, try this:

static void init_pthread_key(void)  {    if (pthread_key_create)   {     pthread_key_create(&pthread_key, release_thread_cache);    } } 

also adding full error checking pthread_* might not during debugging.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -