Changes in benchmark/schedint/pthreads.c [b4107c8:26fd986]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/schedint/pthreads.c
rb4107c8 r26fd986 6 6 volatile int go = 0; 7 7 8 pthread_mutex_t m; 8 9 pthread_cond_t c; 9 pthread_mutex_t m;10 10 11 11 void __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 ); 15 15 } 16 16 17 int__attribute__((noinline)) wait() {17 void __attribute__((noinline)) wait() { 18 18 pthread_mutex_lock(&m); 19 19 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 20 30 BENCH( 21 for (size_t i = 0; i < times; i++) { 22 pthread_cond_wait(&c, &m); 23 }, 31 while ( go == 1 ) { call(); }, 24 32 result 25 33 ) 26 34 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(); }35 35 return NULL; 36 36 } … … 39 39 BENCH_START() 40 40 pthread_t thread; 41 if ( pthread_create(&thread, NULL, thread_main, NULL) < 0) {41 if ( pthread_create( &thread, NULL, thread_main, NULL ) < 0 ) { 42 42 perror( "failure" ); 43 43 return 1; 44 44 } 45 45 wait(); 46 if ( pthread_join( thread, NULL) < 0) {46 if ( pthread_join( thread, NULL ) < 0 ) { 47 47 perror( "failure" ); 48 48 return 1;
Note: See TracChangeset
for help on using the changeset viewer.