-
Notifications
You must be signed in to change notification settings - Fork 1
/
lock_variable.html
450 lines (399 loc) · 15.7 KB
/
lock_variable.html
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lock Variable</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.19.1/css/mdb.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
* {
margin: 0;
padding: 0;
}
body {
background-color: #e6e6e6;
}
body {
font-family: Arial, Helvetica, sans-serif;
margin:0;
padding:0;
}
#navbar {
overflow: hidden;
background-color: #1a1a1a;
}
#navbar a {
float: left;
font-size: 20px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
#dropdown {
float: right;
overflow: hidden;
min-width:260px;
/*position: absolute;
right:50px;*/
}
#dropdown #dropbtn {
font-size: 20px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
width:260px;
}
#navbar a:hover, #dropdown:hover #dropbtn {background-color: red;
}
#dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 260px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
#dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
#dropdown-content a:hover {
background-color: #ddd;
}
#dropdown:hover #dropdown-content {
display: block;
}
#heading {
background-color: #595959;
height: 65px;
text-align: center;
color: #d3d2d2;
width:450px;
margin:auto;
margin-bottom: 50px;
border-bottom-left-radius: 25px;
border-bottom-right-radius: 25px;
}
#user_inp {
display: flex;
flex-direction: column;
width: 20%;
margin: 15px auto;
}
#user_inp>input {
margin-top: 5px;
text-align: center;
border-radius: 10px;
}
#user_inp>button {
margin: auto;
margin-top: 5px;
border-radius: 10px;
width: 50%;
}
#begin {
color: white;
background-color: #6b6969;
border: 1px solid black;
}
.pno {
background-color: #DCDCDC;
border: 2px solid grey;
}
.ent-section {
background-color: rgb(137 135 135 / 50%);
border: 3px solid rgba(0, 0, 0, 0.993);
margin: 15px;
border-radius: 15px;
text-align: center;
font-weight: bold;
}
.ent-items {
background-color: rgb(137 135 135 / 50%);
border: 3px solid rgba(0, 0, 0, 0.993);
margin: 15px;
border-radius: 15px;
text-align: center;
font-weight: bold;
}
.cs-section {
background-color: rgb(137 135 135 / 50%);
border: 3px solid rgba(0, 0, 0, 0.993);
margin: 15px;
border-radius: 15px;
text-align: center;
font-weight: bold;
}
.ext-section {
background-color: rgb(137 135 135 / 50%);
border: 3px solid rgba(0, 0, 0, 0.993);
margin: 15px;
border-radius: 15px;
text-align: center;
font-weight: bold;
}
.lockvariable {
border: 3px solid;
}
.topcorner {
background-color: rgb(137 135 135 / 50%);
position: absolute;
top: 280px;
right: 45px;
border: 3px solid black;
padding: 20px;
border-radius: 10px;
}
p {
margin-bottom: 0px;
}
.codeSection {
background-color: #c0bfbf;
border: 1.5px solid black;
border-radius: 10px;
padding: 5px 10px;
margin-top: 2px;
color: #585656;
}
#TestLock,
#SetLock,
#showCritical,
#showExit,
#waiting-process {
width: 10vw;
margin: auto;
}
#lockdisplay {
margin-left: 4rem;
}
</style>
</head>
<body>
<div id="navbar">
<a href="index.html">Deadlock & Concurrency</a>
<div id="dropdown">
<button id="dropbtn">Algorithms
<i class="fa fa-caret-down"></i>
</button>
<div id="dropdown-content">
<a href="lock_variable.html">Lock Variable</a>
<a href="TSL.html">TSL Mechanism</a>
<a href="turn_variable.html">Turn Variable</a>
<a href="binary_semaphore.html">Binary Semaphore</a>
<a href="counting_semaphore.html">Counting Semaphore</a>
<a href="Peterson's_algorithm.html">Peterson Solution</a>
<a href="p&c.html">Producer & Consumer</a>
<a href="dining_philosophers.html">Dining Philosopher</a>
<a href="Bankers.html">Banker's algorithm</a>
</div>
</div>
</div>
<div id="heading">
<h1 style="padding-top: 6px;">Lock Variable</h1>
</div>
<div class="topcorner">
<p>
<div class="codeSection" id="ent-code"><b style="font-weight: bold;">Entry Section</b><br>While (lock! = 0); </div>
<div class="codeSection" id="crit-code"><b style="font-weight: bold;">Critical Section</b><br>Lock = 1;</div>
<div class="codeSection" id="exit-code"><b style="font-weight: bold;">Exit Section</b><br>Lock =0;</div>
</p>
</div>
<div id="user_inp">
<input type="text" name="process" id="p_no" placeholder="Enter the number of processes">
<button class="btn pno btn-sm" id="begin">Start</button>
</div>
<div class="container-fluid p-4">
<div class="row">
<div class="col-xs-4 col-4" id="processes">
</div>
<div class="col-xs-4 col-4">
<div class="ent-section">
<div class="p-4">
Entry Section
<div class="ent-items p-3">
<div id="lockcheck">
Test Lock
</div>
<div class="btn pno btn-sm px-1" id="TestLock"></div>
</div>
<div class="ent-items p-3">
<div id="lockset">
Set Lock
</div>
<div class="btn pno btn-sm px-1" id="SetLock"></div>
</div>
</div>
</div>
<div class="cs-section">
<div class="p-4">
<div>Crititcal section</div>
<div class="btn pno btn-sm px-1" id="showCritical"></div>
</div>
</div>
<div class="ext-section">
<div class="p-4">
<div>Exit Section</div>
<div class="btn pno btn-sm px-1" id="showExit"></div>
</div>
</div>
</div>
</div>
</div>
<div id="lockdisplay" class="container mt-4 pt-4">
<div class="row">
<div class="col-5">
</div>
<div class="col-3">
<div class="lockvariable" style="border-radius: 7px;">
<div class="text-center" style="background-color: #a3a2a2; border-radius: 5px;">
<!-- Lock Variable -->
<h6 style="padding: 10px;">Lock Value = <span id="svalue"></span></h6>
<div style="border-bottom: 1px solid;"></div>
<div style="padding: 10px;">
<p>Process in Waiting Queue</p>
<div class="btn pno btn-sm px-1" id="waiting-process">
</div>
</div>
</div>
</div>
</div>
<div class="col-1"></div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.19.1/js/mdb.min.js"></script>
<script>
// $('#TestLock #SetLock #showCritical #showExit').css('display', 'none');
$(document).ready(function() {
// $('#TestLock #SetLock #showCritical #showExit').css('display', 'none');
$("#TestLock, #SetLock, #showCritical, #showExit, #waiting-process").css("display", "none");
$("#begin").click(function() {
let testlock = [];
let critical = [];
let exit = [];
let queue = [];
let setlock = [];
let lock = 0;
let process = '';
let p_no = $("#p_no").val();
for (let i = 0; i < p_no; i++) {
process += '<button class="btn pno btn-sm" id="process' + i + '">Process ' + i + '</button><br>'
}
$("#processes").html(process);
$('#waiting-process').text(queue);
$('#svalue').text(lock);
for (let i = 0; i < p_no; i++) {
$('#process' + i).click(function(e) {
e.preventDefault();
runProcess('Process ' + i);
});
}
function runProcess(msg) {
let no = parseInt(msg[8]);
$('#process' + no).hide();
$('#svalue').text(lock);
$('#lockcheck').text('Testing Lock...');
testlock.push(msg);
$('#ent-code').css('color', 'black');
$('#TestLock').css('display', 'block');
$('#TestLock').text(testlock);
$('#svalue').text(lock);
//$('#blocked-process').text(queue);
if (lock == 0) {
setTimeout(() => {
$('#lockcheck').text('Test Lock');
$('#lockset').text('Setting Lock...');
lock = 1;
$('#svalue').text(lock);
testlock = $.grep(testlock, function(value) {
return value != msg;
});
if (testlock.length == 0) {
$('#TestLock').css('display', 'none');
}
$('#TestLock').text(testlock);
setlock.push(msg);
$('#SetLock').text(setlock);
$('#SetLock').css('display', 'block');
setTimeout(() => {
$('#lockset').text('Set Lock');
setlock = $.grep(setlock, function(value) {
return value != msg;
});
if (setlock.length == 0) {
$('#ent-code').css('color', '#585656');
$('#SetLock').css('display', 'none');
}
$('#SetLock').text(setlock);
critical.push(msg);
$('#crit-code').css('color', 'black');
$('#showCritical').css('display', 'block');
$('#showCritical').text(critical);
setTimeout(() => {
critical = $.grep(critical, function(value) {
return value != msg;
});
if (critical.length == 0) {
$('#crit-code').css('color', '#585656');
$('#showCritical').css('display', 'none');
}
$('#showCritical').text(critical);
exit.push(msg);
$('#exit-code').css('color', 'black');
$('#showExit').css('display', 'block');
$('#showExit').text(exit);
setTimeout(() => {
exit = $.grep(exit, function(value) {
return value != msg;
});
if (exit.length == 0) {
$('#exit-code').css('color', '#585656');
$('#showExit').css('display', 'none');
}
$('#showExit').text(exit);
lock = 0;
$('#svalue').text(lock);
if (queue.length != 0) {
let new_process = queue.shift()
$('#waiting-process').text(queue);
runProcess(new_process);
} else {
$('#waiting-process').css('display', 'none');
}
}, 3000);
}, 3000);
}, 1500);
}, 1500);
} else {
setTimeout(() => {
$('#lockcheck').text('Test Lock');
testlock = $.grep(testlock, function(value) {
return value != msg;
});
if (testlock.length == 0) {
$('#TestLock').css('display', 'none');
}
$('#TestLock').text(testlock);
queue.push(msg);
$('#waiting-process').css('display', 'block');
$('#waiting-process').text(queue);
}, 1500);
}
}
});
});
</script>
</body>
</html>