-
Notifications
You must be signed in to change notification settings - Fork 0
/
tickettest.c
56 lines (39 loc) · 798 Bytes
/
tickettest.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
56
#include "types.h"
#include "user.h"
#define NCHILD 15
int main()
{
int pid;
startlock();
pid = fork();
for (int i = 0; i < NCHILD; i++)
if (pid > 0)
pid = fork();
if (pid < 0)
{
printf(2, "fork error\n");
}
else if (pid == 0)
{
capture();
printf(1, "child adding to shared counter\n");
for(int i=0;i<20;i++)
printf(1,"%d\t",i);
printf(1, "\n");
printf(1, "Numbers were printed in a consequtive manner.\n");
printf(1, "No other process is in its critical section.\n");
printf(1, "Thus, mutual exlusion is satisfied!\n");
printf(1, "\n\n");
//sticketlockTest();
withdraw();
}
else
{
while(wait()!=-1);
// sleep(1000);
// for (int i = 0; i < NCHILD; i++)
// wait();
// printf(1, "user program finished \n");
}
exit();
}