1#include <stdlib.h> 2#include <stdio.h> 3#include <pthread.h> 4#include <sched.h> 5 6static void * 7func (void *p) 8{ 9 int *counter = (int *) p; 10 unsigned i; 11 12 for (i=0; i<100; i++) 13 { 14 (*counter) ++; 15 { 16 int array[17]; 17 unsigned x = i % (sizeof(array)/sizeof(array[0])); 18 /* VRP could prove that x is within [0,16], but until then, the 19 following access will ensure that array[] is registered to 20 libmudflap. */ 21 array[x] = i; 22 } 23 sched_yield (); /* sleep (1); */ 24 } 25 26 return (NULL); 27} 28 29 30int main () 31{ 32 int rc; 33 unsigned i; 34 enum foo { NT=10 }; 35 pthread_t threads[NT]; 36 int counts[NT]; 37 38 39 for (i=0; i<NT; i++) 40 { 41 counts[i] = 0; 42 rc = pthread_create (& threads[i], NULL, func, (void *) & counts[i]); 43 if (rc) abort(); 44 } 45 46 for (i=0; i<NT; i++) 47 { 48 rc = pthread_join (threads[i], NULL); 49 if (rc) abort(); 50 printf ("%d%s", counts[i], (i==NT-1) ? "\n" : " "); 51 } 52 53 return 0; 54} 55 56/* { dg-output "100 100 100 100 100 100 100 100 100 100" } */ 57/* { dg-repetitions 20 } */ 58/* { dg-timeout 10 } */ 59