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