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 6f9cc13 was             dc33b5b, checked in by Peter A. Buhr <pabuhr@…>, 6 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 | 
 | 
|---|
| 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("%g\n", result);
 | 
|---|
| 30 |         go = 0;
 | 
|---|
| 31 |         pthread_mutex_unlock(&m);
 | 
|---|
| 32 |         return 0;
 | 
|---|
| 33 | }
 | 
|---|
| 34 | 
 | 
|---|
| 35 | void* thread_main(__attribute__((unused)) void * arg ) {
 | 
|---|
| 36 |         while(go == 0) { sched_yield(); }
 | 
|---|
| 37 |         while(go == 1) { call(); }
 | 
|---|
| 38 |         return NULL;
 | 
|---|
| 39 | }
 | 
|---|
| 40 | 
 | 
|---|
| 41 | int 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.