-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP7P2W.c
More file actions
29 lines (25 loc) · 680 Bytes
/
P7P2W.c
File metadata and controls
29 lines (25 loc) · 680 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <window.h>
#include <stdio.h>
int main(){
HANDLE hSemaforo;
int i=1;
//Apartura del semaforo
if((hSemaforo=OpenSemaphore(SEMAPHORE_ALL_ACCESS,FALSe,"Semaforo"))==NULL){
printf("Falla al invocar OpenSemaphore: %d\n",GetLastError());
return -1;
}
while(i<4){
//Prueba del semaforo
WaitForSingleObject(hSemaforo,INFINITE);
//Seccion critica
printf("Soy el hijo entrando %i de 3 veces al semaforo\n",i);
Sleep(5000);
//Liberando el semaforo
if(!ReleaseSemaphore(hSemaforo,1,NULL)){
printf("Falla al invocar ReleaseSemaphore: %d\n",GetLastError());
}
printf("Soy el hijo liberando %i de 3 veces al semaforo\n",i);
Sleep(5000);
i++;
}
}