* auto-profile.c (afdo_annotate_cfg): Use update_max_bb_count.
[official-gcc.git] / gcc / testsuite / g++.dg / gcov / gcov-threads-1.C
blobb020dd87d4caf61417386b7d7d0d6f2863dfe7b7
1 /* { dg-options "-fprofile-arcs -ftest-coverage -pthread -fprofile-update=atomic" } */
2 /* { dg-do run { target native } } */
3 /* { dg-require-effective-target profile_update_atomic } */
5 #include <stdint.h>
6 #include <pthread.h>
7 #include <assert.h>
9 #define NR 5
11 pthread_mutex_t cndMs[NR];
12 static void *ContentionNoDeadlock_thread(void *start)
14   for (uint32_t k = 0; k < 100000; ++k)         /* count(500005) */
15     {
16       int starti = *(int*)start;                /* count(500000) */
17       for (uint32_t i = starti; i < NR; ++i) 
18         pthread_mutex_lock (&cndMs[i]);
19       for (int32_t i = NR - 1; i >= starti; --i)
20         pthread_mutex_unlock (&cndMs[i]);
21   }
23   return 0;
25 int main(int argc, char **argv) {
26   for (unsigned i = 0; i < NR; i++)
27     cndMs[i] = PTHREAD_MUTEX_INITIALIZER;
29   pthread_t t[NR];
30   int ids[NR];
32   for (int i = 0; i < NR; i++)
33   {
34     ids[i] = i;
35     int r = pthread_create (&t[i], NULL, ContentionNoDeadlock_thread, &ids[i]);
36     assert (r == 0);                            /* count(5*) */
37   }
39   int ret;
40   for (int i = 0; i < NR; i++)
41     {
42       int r = pthread_join (t[i], (void**)&ret);
43       assert (r == 0);                          /* count(5*) */
44     }
46   return 0;                                     /* count(1) */
49 /* { dg-final { run-gcov gcov-threads-1.C } } */