Ignore:
Timestamp:
Feb 4, 2020, 11:29:22 AM (21 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
52142c2, 9f575ea, bdfc032
Parents:
09f357e (diff), e56eb455 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/schedint/pthreads.c

    r09f357e r4f7b418  
    66volatile int go = 0;
    77
     8pthread_mutex_t m;
    89pthread_cond_t c;
    9 pthread_mutex_t m;
    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 int __attribute__((noinline)) wait() {
     17void __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
     27void * 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
    2030        BENCH(
    21                 for (size_t i = 0; i < times; i++) {
    22                         pthread_cond_wait(&c, &m);
    23                 },
     31                while ( go == 1 ) { call(); },
    2432                result
    2533        )
    2634        printf( "%g\n", result );
    27         go = 0;
    28         pthread_mutex_unlock(&m);
    29         return 0;
    30 }
    31 
    32 void* 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.