/* * File : dekker.c * * Title : Demo Race Conditions. * * Short : Software solution for mutex .. dekker * * Long : This programa * * Author : Paul Crocker * * Date : 25 Abril de 2004 */ #include #include #include #define PAUSA(A) fflush(stdin);printf("Pausa %s\n",A);getchar(); #define waitp1 {float indicez1;for(indicez1=0;indicez1<10;indicez1=indicez1+1.0);} #define waitp2 {float indicez1;for(indicez1=0;indicez1<50000;indicez1=indicez1+1.0);} //#define VALOR 100000 #define VALOR 1000 /* variaveis partilhadas pelos threads */ #define VERDADE 1 #define FALSO 0 float x=0; int vez=1; int P1QuerEntrar; int P2QuerEntrar; void *funcao1 (void *args); void *funcao2 (void *args); int main(int argc, char* argv[]) { pthread_t th1,th2; //setbuf(stdout,NULL); PAUSA("Start: Iniciar press return ") pthread_create (&th1, NULL, funcao1, NULL); pthread_create (&th2, NULL, funcao2, NULL); pthread_join ( th2, NULL); pthread_join ( th1, NULL); printf("error = %f\n",x-2.0*VALOR); PAUSA("Fim : press return"); return 0; } void *funcao1 (void *args) { int i; for (i=0;i