source: benchmark/schedint/pthreads.c@ 5ee7d36

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 5ee7d36 was b4107c8, checked in by Peter A. Buhr <pabuhr@…>, 6 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
Line 
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(
21 for (size_t i = 0; i < times; i++) {
22 pthread_cond_wait(&c, &m);
23 },
24 result
25 )
26 printf( "%g\n", result );
27 go = 0;
28 pthread_mutex_unlock(&m);
29 return 0;
30}
31
32void* thread_main(__attribute__((unused)) void * arg ) {
33 while(go == 0) { sched_yield(); }
34 while(go == 1) { call(); }
35 return NULL;
36}
37
38int main( int argc, char * argv[] ) {
39 BENCH_START()
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 }
50}
51
52// Local Variables: //
53// tab-width: 4 //
54// End: //
Note: See TracBrowser for help on using the repository browser.