Hi all,

I have had some luck finding the error which caused this Helgrind
assertion to fail. Not surprisingly it was an error in the debugged
program's code.

A pthread condition variable was being destroyed just after being
signalled, before the other thread would return from the wait function.
Short code reproducing the error is given below.

// CODE BEGIN
#include <iostream>
#include <pthread.h>

pthread_mutex_t mutex;
pthread_cond_t cond;
pthread_t thread;
bool ready = false;

void *ThreadFunction(void *ptr) {
        pthread_mutex_lock(&mutex);
        ready = true;
        pthread_cond_signal(&cond);
        pthread_cond_destroy(&cond); // ERROR!!!
        pthread_mutex_unlock(&mutex);
        return NULL;
}

int main() {
        pthread_mutex_init(&mutex, NULL);
        pthread_cond_init(&cond, NULL);

        pthread_mutex_lock(&mutex);
        pthread_create(&thread, NULL, ThreadFunction, (void*) NULL);
        while (!ready) { // to insure ourselves against spurious wakeups
                pthread_cond_wait(&cond, &mutex);
        }
        pthread_mutex_unlock(&mutex);

        pthread_join(thread, NULL);
        pthread_mutex_destroy(&mutex);
        std::cout << "finished" << std::endl;
        return 0;
}
// CODE END



Martin Heller

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to