ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change
on this file since 5e49e47 was
bf71cfd,
checked in by Thierry Delisle <tdelisle@…>, 6 years ago
|
Moved up many directories in source
|
-
Property mode set to
100644
|
File size:
901 bytes
|
Line | |
---|
1 | #include <pthread.h> |
---|
2 | #include <stdio.h> |
---|
3 | |
---|
4 | #include "bench.h" |
---|
5 | |
---|
6 | int argc; |
---|
7 | char** argv; |
---|
8 | volatile int go = 0; |
---|
9 | |
---|
10 | pthread_cond_t c; |
---|
11 | pthread_mutex_t m; |
---|
12 | |
---|
13 | void __attribute__((noinline)) call() { |
---|
14 | pthread_mutex_lock(&m); |
---|
15 | pthread_cond_signal(&c); |
---|
16 | pthread_mutex_unlock(&m); |
---|
17 | } |
---|
18 | |
---|
19 | int __attribute__((noinline)) wait() { |
---|
20 | pthread_mutex_lock(&m); |
---|
21 | go = 1; |
---|
22 | BENCH( |
---|
23 | for (size_t i = 0; i < n; i++) { |
---|
24 | pthread_cond_wait(&c, &m); |
---|
25 | }, |
---|
26 | result |
---|
27 | ) |
---|
28 | |
---|
29 | printf("%llu\n", result); |
---|
30 | go = 0; |
---|
31 | pthread_mutex_unlock(&m); |
---|
32 | return 0; |
---|
33 | } |
---|
34 | |
---|
35 | void* thread_main(void * a) { |
---|
36 | while(go == 0) { sched_yield(); } |
---|
37 | while(go == 1) { call(); } |
---|
38 | return NULL; |
---|
39 | } |
---|
40 | |
---|
41 | int main(int margc, char* margv[]) { |
---|
42 | argc = margc; |
---|
43 | argv = margv; |
---|
44 | pthread_t thread; |
---|
45 | if (pthread_create(&thread, NULL, thread_main, NULL) < 0) { |
---|
46 | perror( "failure" ); |
---|
47 | return 1; |
---|
48 | } |
---|
49 | wait(); |
---|
50 | if (pthread_join( thread, NULL) < 0) { |
---|
51 | perror( "failure" ); |
---|
52 | return 1; |
---|
53 | } |
---|
54 | return 0; |
---|
55 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.