sewardj | ff42d1d | 2002-05-22 13:17:31 +0000 | [diff] [blame^] | 1 | |
| 2 | #include <stdio.h> |
| 3 | #include <assert.h> |
| 4 | |
| 5 | #define __USE_GNU |
| 6 | #include <pthread.h> |
| 7 | |
| 8 | void do_one_thing ( void* v ) |
| 9 | { |
| 10 | int i, j, res; |
| 11 | for (i = 0; i < 10; i++) { |
| 12 | for (j = 0; j < 10; j++) { |
| 13 | printf("a "); fflush(stdout); |
| 14 | } |
| 15 | printf("\naaaaaaa-yielding\n"); |
| 16 | res = pthread_yield(); |
| 17 | assert(res == 0); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | void do_another_thing ( void* v ) |
| 22 | { |
| 23 | int i, j, res; |
| 24 | for (i = 0; i < 10; i++) { |
| 25 | for (j = 0; j < 10; j++) { |
| 26 | printf("b "); fflush(stdout); |
| 27 | } |
| 28 | printf("\nbbbbbbb-yielding\n"); |
| 29 | res = pthread_yield(); |
| 30 | assert(res == 0); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | |
| 35 | int main ( void ) |
| 36 | { |
| 37 | pthread_t t1, t2; |
| 38 | pthread_create( &t1, NULL, (void*)do_one_thing, NULL ); |
| 39 | pthread_create( &t2, NULL, (void*)do_another_thing, NULL ); |
| 40 | pthread_join(t1, NULL); |
| 41 | pthread_join(t2, NULL); |
| 42 | printf("bye!\n"); |
| 43 | return 0; |
| 44 | } |