-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathestacionamento.c
55 lines (41 loc) · 1.04 KB
/
estacionamento.c
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <semaphore.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define MAXLUGARES 5
#define MAX_CLIENTES 10
pthread_t t_cliente[MAX_CLIENTES];
void entrarNoParque(){
}
void sairDoParque(){
}
void ThreadCarro (){
int espera;
entrarNoParque();
espera = rand() % 20;
printf ("cliente estacionado. Vai demorar %d seg \n", espera);
sleep (espera);
sairDoParque();
printf ("cliente saiu do parque \n");
return;
}
int main () {
int i;
void * resul;
time_t t;
/* Inicializa o gerador de números aleatórios */
srand((unsigned) time(&t));
/* Cria os clientes */
for (i=1; i < MAX_CLIENTES; i++)
{
pthread_create(&t_cliente[i],0, (void*) ThreadCarro, NULL);
printf ("criou o cliente numero %d \n",i);
};
/* Espera que os clientes terminem */
for (i=1; i < MAX_CLIENTES; i++) {
pthread_join(t_cliente[i], &resul);
printf ("terminou cliente %d \n", i);
};
printf (" sistema terminou \n");
}