111
|
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 } */
|
|
4
|
|
5 #include <stdint.h>
|
|
6 #include <pthread.h>
|
|
7 #include <assert.h>
|
|
8
|
|
9 #define NR 5
|
|
10
|
|
11 pthread_mutex_t cndMs[NR];
|
|
12 static void *ContentionNoDeadlock_thread(void *start)
|
|
13 {
|
|
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 }
|
|
22 }
|
|
23 int main(int argc, char **argv) {
|
|
24 for (unsigned i = 0; i < NR; i++)
|
|
25 cndMs[i] = PTHREAD_MUTEX_INITIALIZER;
|
|
26
|
|
27 pthread_t t[NR];
|
|
28 int ids[NR];
|
|
29
|
|
30 for (int i = 0; i < NR; i++)
|
|
31 {
|
|
32 ids[i] = i;
|
|
33 int r = pthread_create (&t[i], NULL, ContentionNoDeadlock_thread, &ids[i]);
|
|
34 assert (r == 0); /* count(5) */
|
|
35 }
|
|
36
|
|
37 int ret;
|
|
38 for (int i = 0; i < NR; i++)
|
|
39 {
|
|
40 int r = pthread_join (t[i], (void**)&ret);
|
|
41 assert (r == 0); /* count(5) */
|
|
42 }
|
|
43
|
|
44 return 0; /* count(1) */
|
|
45 }
|
|
46
|
|
47 /* { dg-final { run-gcov gcov-threads-1.C } } */
|