ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 665f432 was
dc33b5b,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
update benchmarks and add benchmarks for qthreads
|
-
Property mode set to
100644
|
File size:
943 bytes
|
Rev | Line | |
---|
[3eb4541] | 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 | |
---|
[dc33b5b] | 29 | printf("%g\n", result); |
---|
[3eb4541] | 30 | go = 0; |
---|
| 31 | pthread_mutex_unlock(&m); |
---|
| 32 | return 0; |
---|
| 33 | } |
---|
| 34 | |
---|
[dc33b5b] | 35 | void* thread_main(__attribute__((unused)) void * arg ) { |
---|
[3eb4541] | 36 | while(go == 0) { sched_yield(); } |
---|
| 37 | while(go == 1) { call(); } |
---|
| 38 | return NULL; |
---|
| 39 | } |
---|
| 40 | |
---|
[dc33b5b] | 41 | int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[]) { |
---|
[3eb4541] | 42 | pthread_t thread; |
---|
| 43 | if (pthread_create(&thread, NULL, thread_main, NULL) < 0) { |
---|
| 44 | perror( "failure" ); |
---|
| 45 | return 1; |
---|
| 46 | } |
---|
| 47 | wait(); |
---|
| 48 | if (pthread_join( thread, NULL) < 0) { |
---|
| 49 | perror( "failure" ); |
---|
| 50 | return 1; |
---|
| 51 | } |
---|
| 52 | return 0; |
---|
[dc33b5b] | 53 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.