Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/schedint/pthreads.c

    r26fd986 rb4107c8  
    66volatile int go = 0;
    77
     8pthread_cond_t c;
    89pthread_mutex_t m;
    9 pthread_cond_t c;
    1010
    1111void __attribute__((noinline)) call() {
    12         pthread_mutex_lock( &m );
    13         pthread_cond_signal( &c );
    14         pthread_mutex_unlock( &m );
     12        pthread_mutex_lock(&m);
     13        pthread_cond_signal(&c);
     14        pthread_mutex_unlock(&m);
    1515}
    1616
    17 void __attribute__((noinline)) wait() {
     17int __attribute__((noinline)) wait() {
    1818        pthread_mutex_lock(&m);
    1919        go = 1;
    20         for ( size_t i = 0; i < times; i++ ) {
    21                 pthread_cond_wait( &c, &m );
    22         }
    23         go = 0;
    24         pthread_mutex_unlock( &m );
    25 }
    26 
    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
    3020        BENCH(
    31                 while ( go == 1 ) { call(); },
     21                for (size_t i = 0; i < times; i++) {
     22                        pthread_cond_wait(&c, &m);
     23                },
    3224                result
    3325        )
    3426        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(); }
    3535        return NULL;
    3636}
     
    3939        BENCH_START()
    4040        pthread_t thread;
    41         if ( pthread_create( &thread, NULL, thread_main, NULL ) < 0 ) {
     41        if (pthread_create(&thread, NULL, thread_main, NULL) < 0) {
    4242                perror( "failure" );
    4343                return 1;
    4444        }
    4545        wait();
    46         if ( pthread_join( thread, NULL ) < 0 ) {
     46        if (pthread_join( thread, NULL) < 0) {
    4747                perror( "failure" );
    4848                return 1;
Note: See TracChangeset for help on using the changeset viewer.