drd: Add a consistency check
[valgrind.git] / memcheck / tests / threadname.c
blob91e7f833eb8b60ac4862bef02d84bd2db7b276f7
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <pthread.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <sys/types.h>
7 #include <unistd.h>
8 #include <assert.h>
11 static pthread_t children[3];
13 void bad_things(int offset)
15 char* m = malloc(sizeof(char)*offset);
16 m[offset] = 0;
17 free(m);
20 void* child_fn_2 ( void* arg )
22 const char* threadname = "012345678901234";
24 # if !defined(VGO_darwin)
25 pthread_setname_np(pthread_self(), threadname);
26 # else
27 pthread_setname_np(threadname);
28 # endif
30 bad_things(4);
32 return NULL;
35 void* child_fn_1 ( void* arg )
37 const char* threadname = "try1";
38 int r;
40 # if !defined(VGO_darwin)
41 pthread_setname_np(pthread_self(), threadname);
42 # else
43 pthread_setname_np(threadname);
44 # endif
46 bad_things(3);
48 r = pthread_create(&children[2], NULL, child_fn_2, NULL);
49 assert(!r);
51 r = pthread_join(children[2], NULL);
52 assert(!r);
54 return NULL;
57 void* child_fn_0 ( void* arg )
59 int r;
61 bad_things(2);
63 r = pthread_create(&children[1], NULL, child_fn_1, NULL);
64 assert(!r);
66 r = pthread_join(children[1], NULL);
67 assert(!r);
69 return NULL;
72 int main(int argc, const char** argv)
74 int r;
76 bad_things(1);
78 r = pthread_create(&children[0], NULL, child_fn_0, NULL);
79 assert(!r);
81 r = pthread_join(children[0], NULL);
82 assert(!r);
84 bad_things(5);
86 return 0;