Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/schedint/pthreads.c

    r26fd986 rdc33b5b  
    44#include "bench.h"
    55
     6int argc;
     7char** argv;
    68volatile int go = 0;
    79
     10pthread_cond_t c;
    811pthread_mutex_t m;
    9 pthread_cond_t c;
    1012
    1113void __attribute__((noinline)) call() {
    12         pthread_mutex_lock( &m );
    13         pthread_cond_signal( &c );
    14         pthread_mutex_unlock( &m );
     14        pthread_mutex_lock(&m);
     15        pthread_cond_signal(&c);
     16        pthread_mutex_unlock(&m);
    1517}
    1618
    17 void __attribute__((noinline)) wait() {
     19int __attribute__((noinline)) wait() {
    1820        pthread_mutex_lock(&m);
    1921        go = 1;
    20         for ( size_t i = 0; i < times; i++ ) {
    21                 pthread_cond_wait( &c, &m );
    22         }
     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);
    2330        go = 0;
    24         pthread_mutex_unlock( &m );
     31        pthread_mutex_unlock(&m);
     32        return 0;
    2533}
    2634
    27 void * thread_main( __attribute__((unused)) void * arg ) {
    28         while ( go == 0 ) { sched_yield(); } // waiter must start first
    29         // barging for lock acquire => may not execute N times
    30         BENCH(
    31                 while ( go == 1 ) { call(); },
    32                 result
    33         )
    34         printf( "%g\n", result );
     35void* thread_main(__attribute__((unused)) void * arg ) {
     36        while(go == 0) { sched_yield(); }
     37        while(go == 1) { call(); }
    3538        return NULL;
    3639}
    3740
    38 int main( int argc, char * argv[] ) {
    39         BENCH_START()
     41int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[]) {
    4042        pthread_t thread;
    41         if ( pthread_create( &thread, NULL, thread_main, NULL ) < 0 ) {
     43        if (pthread_create(&thread, NULL, thread_main, NULL) < 0) {
    4244                perror( "failure" );
    4345                return 1;
    4446        }
    4547        wait();
    46         if ( pthread_join( thread, NULL ) < 0 ) {
     48        if (pthread_join( thread, NULL) < 0) {
    4749                perror( "failure" );
    4850                return 1;
    4951        }
     52        return 0;
    5053}
    51 
    52 // Local Variables: //
    53 // tab-width: 4 //
    54 // End: //
Note: See TracChangeset for help on using the changeset viewer.