source: benchmark/schedint/pthreads.c @ dc33b5b

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since dc33b5b 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
Line 
1#include <pthread.h>
2#include <stdio.h>
3
4#include "bench.h"
5
6int argc;
7char** argv;
8volatile int go = 0;
9
10pthread_cond_t c;
11pthread_mutex_t m;
12
13void __attribute__((noinline)) call() {
14        pthread_mutex_lock(&m);
15        pthread_cond_signal(&c);
16        pthread_mutex_unlock(&m);
17}
18
19int  __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("%g\n", result);
30        go = 0;
31        pthread_mutex_unlock(&m);
32        return 0;
33}
34
35void* thread_main(__attribute__((unused)) void * arg ) {
36        while(go == 0) { sched_yield(); }
37        while(go == 1) { call(); }
38        return NULL;
39}
40
41int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[]) {
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;
53}
Note: See TracBrowser for help on using the repository browser.