mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-03 18:13:01 +00:00
* when cond var is destroyed, in the PRE, report an error if nwaiters > 0. * when cond_wait succeeds, get the cond var but do not create one in helgrind (it must exist if cond_wait was done). Report an error if cond not found (assuming this is caused by a destroy done while the thread was cond_wait-ing). * added a test git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12721
40 lines
976 B
C
40 lines
976 B
C
#include <stdio.h>
|
|
#include <pthread.h>
|
|
#include <errno.h>
|
|
// test program from johan.walles (bug 295590)
|
|
// This test verifies that helgrind detects (and does not crash) when
|
|
// the guest application wrongly destroys a cond var being waited
|
|
// upon.
|
|
pthread_mutex_t mutex;
|
|
pthread_cond_t cond;
|
|
pthread_t thread;
|
|
int ready = 0;
|
|
|
|
void *ThreadFunction(void *ptr)
|
|
{
|
|
pthread_mutex_lock(&mutex);
|
|
ready = 1;
|
|
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);
|
|
printf("finished\n");
|
|
return 0;
|
|
}
|