Changeset bdfc032 for benchmark/schedint/pthreads.c
- Timestamp:
- Feb 4, 2020, 11:35:26 AM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- eef8dfb
- Parents:
- aefb247 (diff), 4f7b418 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/schedint/pthreads.c
raefb247 rbdfc032 4 4 #include "bench.h" 5 5 6 int argc;7 char** argv;8 6 volatile int go = 0; 9 7 8 pthread_mutex_t m; 10 9 pthread_cond_t c; 11 pthread_mutex_t m;12 10 13 11 void __attribute__((noinline)) call() { 14 pthread_mutex_lock( &m);15 pthread_cond_signal( &c);16 pthread_mutex_unlock( &m);12 pthread_mutex_lock( &m ); 13 pthread_cond_signal( &c ); 14 pthread_mutex_unlock( &m ); 17 15 } 18 16 19 int__attribute__((noinline)) wait() {17 void __attribute__((noinline)) wait() { 20 18 pthread_mutex_lock(&m); 21 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 22 30 BENCH( 23 for (size_t i = 0; i < n; i++) { 24 pthread_cond_wait(&c, &m); 25 }, 31 while ( go == 1 ) { call(); }, 26 32 result 27 33 ) 28 29 printf("%g\n", result); 30 go = 0; 31 pthread_mutex_unlock(&m); 32 return 0; 33 } 34 35 void* thread_main(__attribute__((unused)) void * arg ) { 36 while(go == 0) { sched_yield(); } 37 while(go == 1) { call(); } 34 printf( "%g\n", result ); 38 35 return NULL; 39 36 } 40 37 41 int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[]) { 38 int main( int argc, char * argv[] ) { 39 BENCH_START() 42 40 pthread_t thread; 43 if ( pthread_create(&thread, NULL, thread_main, NULL) < 0) {41 if ( pthread_create( &thread, NULL, thread_main, NULL ) < 0 ) { 44 42 perror( "failure" ); 45 43 return 1; 46 44 } 47 45 wait(); 48 if ( pthread_join( thread, NULL) < 0) {46 if ( pthread_join( thread, NULL ) < 0 ) { 49 47 perror( "failure" ); 50 48 return 1; 51 49 } 52 return 0;53 50 } 51 52 // Local Variables: // 53 // tab-width: 4 // 54 // End: //
Note: See TracChangeset
for help on using the changeset viewer.