Changes in benchmark/schedint/pthreads.c [26fd986:dc33b5b]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/schedint/pthreads.c
r26fd986 rdc33b5b 4 4 #include "bench.h" 5 5 6 int argc; 7 char** argv; 6 8 volatile int go = 0; 7 9 10 pthread_cond_t c; 8 11 pthread_mutex_t m; 9 pthread_cond_t c;10 12 11 13 void __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); 15 17 } 16 18 17 void__attribute__((noinline)) wait() {19 int __attribute__((noinline)) wait() { 18 20 pthread_mutex_lock(&m); 19 21 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); 23 30 go = 0; 24 pthread_mutex_unlock( &m ); 31 pthread_mutex_unlock(&m); 32 return 0; 25 33 } 26 34 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 ); 35 void* thread_main(__attribute__((unused)) void * arg ) { 36 while(go == 0) { sched_yield(); } 37 while(go == 1) { call(); } 35 38 return NULL; 36 39 } 37 40 38 int main( int argc, char * argv[] ) { 39 BENCH_START() 41 int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[]) { 40 42 pthread_t thread; 41 if ( pthread_create( &thread, NULL, thread_main, NULL ) < 0) {43 if (pthread_create(&thread, NULL, thread_main, NULL) < 0) { 42 44 perror( "failure" ); 43 45 return 1; 44 46 } 45 47 wait(); 46 if ( pthread_join( thread, NULL ) < 0) {48 if (pthread_join( thread, NULL) < 0) { 47 49 perror( "failure" ); 48 50 return 1; 49 51 } 52 return 0; 50 53 } 51 52 // Local Variables: //53 // tab-width: 4 //54 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.