int main() { int tid1 = picreate(30, &mutexFunc1, NULL); int tid2 = picreate(30, &mutexFunc2, NULL); i = (int*) malloc(sizeof(int)); *i = 0; if(pimutex_init(&mutex) == 0) printf("\n\t\t* mutex init OK! *\t\t\n"); piwait(tid1); piwait(tid2); printf("\t\tterminating main\n"); return 0; }
void* mutexFunc2() { int tid = picreate(30, &calcFunc, NULL); printf("\t\tentrando em mutexFunc2!\n"); pilock(&mutex); printf("\t\tchamando piwait em mutexFunc2!\n"); piwait(tid); printf("\t\ti = %d\n", *i); piunlock(&mutex); printf("\t\t * terminando mutexFunc2!\n"); return NULL; }
int main(int argc, char *argv[]) { int i = 144; int id0, id1;//, id2, id3, id4; //printf("Resultado piwait: %d\n", piwait(id0)); //printf("&i = 0x%08x\n",&i); id0 = picreate(20, func0, (void *)&i); id1 = picreate(30, func1, (void *)&i); //i = piwait(id1); i = piwait(id0); //printf("ID1: %d ID2: %d\n", id0, id1); //printf("ID2: %d\n", picreate(4, func0, (void *)&i)); //printf("ID3: %d\n", picreate(5, func0, (void *)&i)); //printf("ID4: %d\n", picreate(6, func0, (void *)&i)); //func0((void *)&i); return 0; }