core: Pass stack change user requests on to tools
[valgrind.git] / callgrind / tests / threads.c
blobb38c0a3e604c4b1fb5557f6928705d4c71a7de1d
1 /* A simple example with 4 threads */
3 #include <pthread.h>
4 #include <unistd.h>
6 double a[1000];
8 static void init()
10 int i;
11 for(i=0;i<1000;i++) a[i] = (double)i;
14 static void *th(void *v)
16 double sum = 0.0;
17 int i,j;
19 for(j=0;j<1000;j++)
20 for(i=0;i<1000;i++)
21 sum += a[i];
23 *( (double*)v ) = sum;
25 /* make sure that no threads is so fast that it finishes
26 * before last thread is created, thus reusing the TID */
27 sleep(1);
29 return 0;
32 int main()
34 pthread_t t[4];
35 double sum[4];
36 int i;
38 init();
40 for(i=0;i<4;i++)
41 pthread_create(&t[i], NULL, th, &sum[i]);
43 for(i=0;i<4;i++)
44 pthread_join(t[i], NULL);
46 return 0;