Add DRD suppression patterns for races triggered by std::ostream
[valgrind.git] / helgrind / tests / locked_vs_unlocked1.c
blob96dc425480403124a07acc960d3d16ca2e8a65de
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
7 /* Test of the mechanism for showing all locks held by a thread -- one
8 thread has a lock, the other doesn't. Running w/ command line args
9 switches the has/has-not thread around, so as to test lockset
10 retention in both the history mechanism and the primary errors. */
12 pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;
14 int x = 0;
16 void* child_fn ( void* arg )
18 if (arg) pthread_mutex_lock(&mx);
19 x = 1;
20 if (arg) pthread_mutex_unlock(&mx);
21 return NULL;
24 int main ( int argc, char** argv )
26 int sw = argc > 1;
27 pthread_t child1, child2;
29 if (pthread_create(&child1, NULL, child_fn, (void*)(long)(sw ? 0 : 1))) {
30 perror("pthread_create1");
31 exit(1);
33 sleep(1); /* ensure repeatable results */
34 if (pthread_create(&child2, NULL, child_fn, (void*)(long)(sw ? 1 : 0))) {
35 perror("pthread_create1");
36 exit(1);
39 if (pthread_join(child1, NULL)) {
40 perror("pthread join1");
41 exit(1);
44 if (pthread_join(child2, NULL)) {
45 perror("pthread join2");
46 exit(1);
49 return 0;