1 /* Compiler options: 2 #cc: additional_flags=-pthread 3 #notarget: cris*-*-elf 4 5 To test sched_yield in the presencs of threads. Core from ex1.c. */ 6 7 #include <stddef.h> 8 #include <stdio.h> 9 #include <unistd.h> 10 #include <pthread.h> 11 #include <stdlib.h> 12 13 static void * process(void * arg)14process (void *arg) 15 { 16 int i; 17 for (i = 0; i < 10; i++) 18 { 19 if (sched_yield () != 0) 20 abort (); 21 } 22 return NULL; 23 } 24 25 int main(void)26main (void) 27 { 28 int retcode; 29 pthread_t th_a, th_b; 30 void *retval; 31 32 retcode = pthread_create (&th_a, NULL, process, (void *) "a"); 33 if (retcode != 0) 34 abort (); 35 retcode = pthread_create (&th_b, NULL, process, (void *) "b"); 36 if (retcode != 0) 37 abort (); 38 retcode = pthread_join (th_a, &retval); 39 if (retcode != 0) 40 abort (); 41 retcode = pthread_join (th_b, &retval); 42 if (retcode != 0) 43 abort (); 44 printf ("pass\n"); 45 return 0; 46 } 47