pthread_cond_wait: losowy błąd segmentacji

Aktualizacja 3

ostatnio zauważyłem, że mój kod losowo powodujeBłąd segmentacji błędy. Ale myślę, że mój kod jest dość prosty i nie mogę się zorientować, skąd ten błąd pochodzi. Ponieważ dzieje się to losowo, zakładam, że istnieje jakiś rodzaj kondycji rasowej. Myślę, że to cały kod, który może być odpowiedni, powiedz mi, jeśli potrzebujesz więcej:

namespace thread {
    pthread_t terminated_thread_id, /* and others */;
    pthread_mutex_t terminate_thread = PTHREAD_MUTEX_INITIALIZER;
    pthread_cond_t terminate_thread_signal = PTHREAD_COND_INITIALIZER;
    int total_thread_count = 0;
    int termination; // + sembufs

    inline void* Exit(void* value) {
    //  This must be unlocked after all join-related jobs are done
        semop(thread::termination, thread::termination_in_process, 2)
            pthread_mutex_lock(&thread::terminate_thread);
                thread::terminated_thread_id = pthread_self();
                pthread_cond_signal(&thread::terminate_thread_signal);
            pthread_mutex_unlock(&thread::terminate_thread);

        pthread_exit(value);
        return value;
    }
}
int main(int argc, const char** argv){
...
    pthread_mutex_lock(&thread::terminate_thread);
    if(0 != pthread_create(&thread::communication_handler_thread_id, NULL,    \
                           CommunicationHandler, NULL)){
        global::PrintDebug("pthread_create() failed", __FILE__, __LINE__);
    }
    /** 2 more pthread_create()-calls */       
    do{
        thread::terminated_thread_id = pthread_self();
        pthread_cond_wait(&thread::terminate_thread_signal,                   \
                          &thread::terminate_thread);
        if(!pthread_equal(thread::terminated_thread_id, pthread_self())){
            pthread_join(thread::terminated_thread_id, NULL);
    ...
            semop(thread::termination, thread::termination_done, 1)
        }
    }while(thread::total_thread_count > 0);

    pthread_mutex_unlock(&thread::terminate_thread);
    return 0;
}

Sygnałterminate_thread_signal jest emitowany tylko wthread :: Exit () funkcjonować. Ta funkcja jest również wywoływana tylko na końcu funkcji używanej do tworzenia wątku.

Oto, co pokazuje debugger dla stosu połączeń:

#0 (    0xb7fe2424 in __kernel_vsyscall() (??:??)
#1 0xb7fbdfcf   __pthread_cond_wait(cond=0x80539c0, mutex=0x8053998) (pthread_cond_wait.c:153)
#2 0x804a094    main(argc=1, argv=0xbffff9c4) (/home/papergay/SeekYourCar/0.2/Server/main.cpp:121)

Wiem, że jeśli błąd się wydarzy, żaden wątek nie wywołał jeszcze wątku :: Exit (). Używam także nienazwanej przestrzeni nazw z kilkoma inicjalizacjami (jeśli to może być istotne). Używam Code :: Blocks jako IDE i GCC jako kompilatora.

questionAnswers(3)

yourAnswerToTheQuestion