ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since db62eef was
51493a4,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
start directory for full-contention mutex tests
|
-
Property mode set to
100644
|
File size:
857 bytes
|
Rev | Line | |
---|
[51493a4] | 1 | #include <pthread.h> |
---|
| 2 | #include <stdio.h> |
---|
| 3 | #include <stdbool.h> |
---|
| 4 | |
---|
| 5 | #include "../bench.h" |
---|
| 6 | |
---|
| 7 | pthread_mutex_t mutex; |
---|
| 8 | |
---|
| 9 | volatile bool go = false; |
---|
| 10 | |
---|
| 11 | void call() { |
---|
| 12 | go = true; |
---|
| 13 | for ( size_t i = 0; i < times; i += 1 ) { |
---|
| 14 | pthread_mutex_lock( &mutex ); |
---|
| 15 | pthread_mutex_unlock( &mutex ); |
---|
| 16 | } |
---|
| 17 | go = false; |
---|
| 18 | } |
---|
| 19 | void * thread_main( __attribute__((unused)) void * arg ) { |
---|
| 20 | while ( ! go ); |
---|
| 21 | while ( go ) { |
---|
| 22 | pthread_mutex_lock( &mutex ); |
---|
| 23 | pthread_mutex_unlock( &mutex ); |
---|
| 24 | } |
---|
| 25 | return NULL; |
---|
| 26 | } |
---|
| 27 | int main( int argc, char * argv[] ) { |
---|
| 28 | BENCH_START() |
---|
| 29 | pthread_t thread; |
---|
| 30 | if ( pthread_create( &thread, NULL, thread_main, NULL ) < 0 ) { |
---|
| 31 | perror( "failure" ); |
---|
| 32 | return EXIT_FAILURE; |
---|
| 33 | } |
---|
| 34 | BENCH( |
---|
| 35 | call(), |
---|
| 36 | result |
---|
| 37 | ) |
---|
| 38 | printf( "%g\n", result ); |
---|
| 39 | if ( pthread_join( thread, NULL ) < 0 ) { |
---|
| 40 | perror( "failure" ); |
---|
| 41 | return EXIT_FAILURE; |
---|
| 42 | } |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | // Local Variables: // |
---|
| 46 | // tab-width: 4 // |
---|
| 47 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.