source: benchmark/schedint/pthreads.c @ 2316525

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 2316525 was b4107c8, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

update existing benchmarks for changes to bench.h, add new benchmarks in new programming languages

  • Property mode set to 100644
File size: 938 bytes
RevLine 
[3eb4541]1#include <pthread.h>
2#include <stdio.h>
3
4#include "bench.h"
5
6volatile int go = 0;
7
8pthread_cond_t c;
9pthread_mutex_t m;
10
11void __attribute__((noinline)) call() {
12        pthread_mutex_lock(&m);
13        pthread_cond_signal(&c);
14        pthread_mutex_unlock(&m);
15}
16
17int  __attribute__((noinline)) wait() {
18        pthread_mutex_lock(&m);
19        go = 1;
20        BENCH(
[b4107c8]21                for (size_t i = 0; i < times; i++) {
[3eb4541]22                        pthread_cond_wait(&c, &m);
23                },
24                result
25        )
[b4107c8]26        printf( "%g\n", result );
[3eb4541]27        go = 0;
28        pthread_mutex_unlock(&m);
29        return 0;
30}
31
[dc33b5b]32void* thread_main(__attribute__((unused)) void * arg ) {
[3eb4541]33        while(go == 0) { sched_yield(); }
34        while(go == 1) { call(); }
35        return NULL;
36}
37
[b4107c8]38int main( int argc, char * argv[] ) {
39        BENCH_START()
[3eb4541]40        pthread_t thread;
41        if (pthread_create(&thread, NULL, thread_main, NULL) < 0) {
42                perror( "failure" );
43                return 1;
44        }
45        wait();
46        if (pthread_join( thread, NULL) < 0) {
47                perror( "failure" );
48                return 1;
49        }
[dc33b5b]50}
[b4107c8]51
52// Local Variables: //
53// tab-width: 4 //
54// End: //
Note: See TracBrowser for help on using the repository browser.