-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_2_final.c
650 lines (629 loc) · 20.6 KB
/
project_2_final.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
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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
#include "queue.c"
#include <sys/time.h>
#include <pthread.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
int simulationTime = 120; // simulation time
int seed = 10; // seed for randomness
int emergencyFrequency = 40; // frequency of emergency
float p = 0.2; // probability of a ground job (launch & assembly)
int n = 30; // set n if it does not given in arguments
// time related variables
struct timeval start_time;
struct timeval current_time;
struct timeval current_time_ct;
long start_sc;
long end_sc;
int doneEmergency = 0;
// Used for round robin for pads a and b. If one type has priority but the queue is
// empty, then the other can use it
pthread_mutex_t a_priority_mutex = PTHREAD_MUTEX_INITIALIZER;
int pad_a_priority = 1;
pthread_mutex_t b_priority_mutex = PTHREAD_MUTEX_INITIALIZER;
int pad_b_priority = 1;
pthread_mutex_t max_wait_mutex = PTHREAD_MUTEX_INITIALIZER;
int maxWaitTime = 0;
int previous_a_priority;
int previous_b_priority;
pthread_mutex_t prev_a_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t prev_b_mutex = PTHREAD_MUTEX_INITIALIZER;
// job queues:
Queue *launch_queue;
Queue *land_queue;
Queue *assembly_queue;
Queue *emergency_queue;
Queue *padA_queue;
Queue *padB_queue;
// global variable for unique IDs
int JobID = 0;
// mutex for unique id creation
pthread_mutex_t id_mutex = PTHREAD_MUTEX_INITIALIZER;
// mutexes for job queues
pthread_mutex_t land_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t launch_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t assembly_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t emergency_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
// mutexes for pad queues
pthread_mutex_t padA_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t padB_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
// queue log mutex
pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
// logging file
FILE *events_log;
void *LandingJob(void *arg);
void *LaunchJob(void *arg);
void *EmergencyJob(void *arg);
void *AssemblyJob(void *arg);
void *ControlTower(void *arg);
void *PadA(void *arg);
void *PadB(void *arg);
void *SnapShotPrint(void *arg);
// pthread sleeper function
int pthread_sleep(int seconds)
{
pthread_mutex_t mutex;
pthread_cond_t conditionvar;
struct timespec timetoexpire;
if (pthread_mutex_init(&mutex, NULL))
{
return -1;
}
if (pthread_cond_init(&conditionvar, NULL))
{
return -1;
}
struct timeval tp;
// When to expire is an absolute time, so get the current time and add it to our delay time
gettimeofday(&tp, NULL);
timetoexpire.tv_sec = tp.tv_sec + seconds;
timetoexpire.tv_nsec = tp.tv_usec * 1000;
pthread_mutex_lock(&mutex);
int res = pthread_cond_timedwait(&conditionvar, &mutex, &timetoexpire);
pthread_mutex_unlock(&mutex);
pthread_mutex_destroy(&mutex);
pthread_cond_destroy(&conditionvar);
// Upon successful completion, a value of zero shall be returned
return res;
}
int main(int argc, char **argv)
{
// -p (float) => sets p
// -t (int) => simulation time in seconds
// -s (int) => change the random seed
for (int i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-p"))
{
p = atof(argv[++i]);
}
else if (!strcmp(argv[i], "-t"))
{
simulationTime = atoi(argv[++i]);
}
else if (!strcmp(argv[i], "-s"))
{
seed = atoi(argv[++i]);
}
else if (!strcmp(argv[i], "-n"))
{
n = atoi(argv[++i]);
}
}
// get current, start end times decide the end time in seconds
gettimeofday(¤t_time, NULL);
gettimeofday(&start_time, NULL);
start_sc = (long)start_time.tv_sec;
end_sc = start_sc + simulationTime;
srand(seed); // feed the seed
// logging
events_log = fopen("./events.log", "w");
fprintf(events_log, "EventID\tStatus\tRequest Time\tEnd Time\tTurnaround Time\tPad\n");
// Initialize queues for each job type and for pad A and B
launch_queue = ConstructQueue(1000);
land_queue = ConstructQueue(1000);
assembly_queue = ConstructQueue(1000);
emergency_queue = ConstructQueue(1000);
padA_queue = ConstructQueue(1000);
padB_queue = ConstructQueue(1000);
//fprintf(events_log, "queues created\n");
// Create Control Tower and one thread that is responsible for one job type for each job type
pthread_t ct_thread, snapshot_thread, emergency_thread, landing_thread, launch_thread, assembly_thread, padA_thread, padB_thread;
pthread_create(&landing_thread, NULL, LandingJob, NULL);
pthread_create(&launch_thread, NULL, LaunchJob, NULL);
pthread_create(&assembly_thread, NULL, AssemblyJob, NULL);
pthread_create(&emergency_thread, NULL, EmergencyJob, NULL);
pthread_create(&ct_thread, NULL, ControlTower, NULL);
pthread_create(&padA_thread, NULL, PadA, NULL);
pthread_create(&padB_thread, NULL, PadB, NULL);
pthread_create(&snapshot_thread, NULL, SnapShotPrint, NULL);
//fprintf(events_log, "threads created\n");
// join threads for synch (given in documentation)
pthread_join(landing_thread, NULL);
pthread_join(launch_thread, NULL);
pthread_join(assembly_thread, NULL);
pthread_join(ct_thread, NULL);
pthread_join(padA_thread, NULL);
pthread_join(padB_thread, NULL);
// fprintf(events_log,"joins created\n");
// your code goes here
// fprintf(events_log,"close created\n");
fclose(events_log);
DestructQueue(land_queue);
DestructQueue(launch_queue);
DestructQueue(assembly_queue);
DestructQueue(padA_queue);
DestructQueue(padB_queue);
return 0;
}
//SnapShotPrint is a thread that in every n seconds prints queues
void* SnapShotPrint(void *arg){
struct timeval current_time;
gettimeofday(¤t_time, NULL);
long sim_time = current_time.tv_sec - start_sc;
while (current_time.tv_sec < end_sc){
sim_time = current_time.tv_sec - start_sc;
//printf("%ld", sim_time % n);
if(n <= sim_time && ((int) sim_time %(int)n == 0)){
printQueue(land_queue, sim_time, 1);
printQueue(launch_queue, sim_time, 2);
printQueue(assembly_queue, sim_time, 3);
}
pthread_sleep(n);
gettimeofday(¤t_time, NULL);
}
}
// Landing Job Thread that controls all land jobs
// assume this is type 1
void *LandingJob(void *arg)
{
struct timeval current_time;
gettimeofday(¤t_time, NULL);
// create landing job until time is out with probability 1-p
double rand_p;
while (current_time.tv_sec < end_sc)
{
// fprintf(events_log,"inside L while\n");
rand_p = (double)rand() / (double)RAND_MAX;
if (rand_p < 1 - p)
{
Job landing;
pthread_mutex_lock(&id_mutex);
landing.ID = JobID++;
pthread_mutex_unlock(&id_mutex);
landing.type = 1;
landing.request_time = current_time;
pthread_mutex_lock(&land_queue_mutex);
Enqueue(land_queue, landing);
pthread_mutex_unlock(&land_queue_mutex);
//fprintf(events_log, "Landing created\n");
}
// t=2 as given in instructions
pthread_sleep(2);
// update current time
gettimeofday(¤t_time, NULL);
}
pthread_exit(NULL);
}
// Launch Job Thread that controls all launch jobs
void *LaunchJob(void *arg)
{
struct timeval current_time;
gettimeofday(¤t_time, NULL);
// create launch job until time is out with probability p/2
double rand_p;
while (current_time.tv_sec < end_sc)
{
rand_p = (double)rand() / (double)RAND_MAX;
if (rand_p < p / 2)
{
Job launch;
pthread_mutex_lock(&id_mutex);
launch.ID = JobID++;
pthread_mutex_unlock(&id_mutex);
launch.type = 2;
launch.request_time = current_time;
pthread_mutex_lock(&launch_queue_mutex);
Enqueue(launch_queue, launch);
pthread_mutex_unlock(&launch_queue_mutex);
//fprintf(events_log, "Launch created\n");
}
// t=2 as given in instructions
pthread_sleep(2);
// update current time
gettimeofday(¤t_time, NULL);
}
pthread_exit(NULL);
}
// Landing Job Thread that controls all emergency jobs
void *EmergencyJob(void *arg)
{
struct timeval current_time;
gettimeofday(¤t_time, NULL);
//long timeSinceLastEmergency
while (current_time.tv_sec < end_sc)
{
if ((current_time.tv_sec - start_sc) % 40 == 0 && (current_time.tv_sec - start_sc) >= 40)
{
if(doneEmergency == 0) {
Job emergency1;
Job emergency2;
pthread_mutex_lock(&id_mutex);
emergency1.ID = JobID++;
emergency2.ID = JobID++;
pthread_mutex_unlock(&id_mutex);
emergency1.type = 4;
emergency2.type = 4;
emergency1.request_time = current_time;
emergency2.request_time = current_time;
pthread_mutex_lock(&emergency_queue_mutex);
Enqueue(emergency_queue, emergency1);
Enqueue(emergency_queue, emergency2);
pthread_mutex_unlock(&emergency_queue_mutex);
//fprintf(events_log, "Emergencies created.\n");
pthread_mutex_lock(&a_priority_mutex);
pthread_mutex_lock(&prev_a_mutex);
previous_a_priority = pad_a_priority;
pad_a_priority = 4;
pthread_mutex_unlock(&prev_a_mutex);
pthread_mutex_unlock(&a_priority_mutex);
pthread_mutex_lock(&b_priority_mutex);
pthread_mutex_lock(&prev_b_mutex);
previous_b_priority = pad_b_priority;
pad_b_priority = 4;
pthread_mutex_unlock(&prev_b_mutex);
pthread_mutex_unlock(&b_priority_mutex);
doneEmergency = 1;
}
}
else {
doneEmergency = 0;
}
if ((current_time.tv_sec - start_sc) % n == 0 && (current_time.tv_sec - start_sc) >= n)
{
pthread_mutex_lock(&print_mutex);
printQueue(emergency_queue, current_time.tv_sec - start_sc, 4);
pthread_mutex_unlock(&print_mutex);
}
gettimeofday(¤t_time, NULL);
pthread_sleep(2);
}
pthread_exit(NULL);
}
// Assembly Job Thread that controls all assembly jobs
void *AssemblyJob(void *arg)
{
struct timeval current_time;
gettimeofday(¤t_time, NULL);
// create assembly job until time is out with probability p/2
double rand_p;
while (current_time.tv_sec < end_sc)
{
rand_p = (double)rand() / (double)RAND_MAX;
if (rand_p < p / 2)
{
Job assembly;
pthread_mutex_lock(&id_mutex);
assembly.ID = JobID++;
pthread_mutex_unlock(&id_mutex);
assembly.type = 3;
assembly.request_time = current_time;
pthread_mutex_lock(&assembly_queue_mutex);
Enqueue(assembly_queue, assembly);
pthread_mutex_unlock(&assembly_queue_mutex);
//fprintf(events_log, "Assembly created\n");
}
// t=2 as given in instructions
pthread_sleep(2);
// update current time
gettimeofday(¤t_time, NULL);
}
pthread_exit(NULL);
}
// Pad A thread that controls the actions on pad A
void *PadA(void *arg)
{
// fprintf(events_log,"pad a thread is created\n");
struct timeval current_time;
gettimeofday(¤t_time, NULL);
while (current_time.tv_sec < end_sc)
{
// fprintf(events_log,"inside pad a\n");
pthread_mutex_lock(&padA_queue_mutex);
// if there is an job is in pad A than do not need to control until it is done
if (!isEmpty(padA_queue))
{
// pthread_mutex_unlock(&padA_queue_mutex);
int job_type = padA_queue->head->data.type;
pthread_mutex_unlock(&padA_queue_mutex);
if (job_type == 2)
{
struct timeval finishedWaiting;
gettimeofday(&finishedWaiting, NULL);
int waitingTime = finishedWaiting.tv_sec - padA_queue->head->data.request_time.tv_sec;
pthread_mutex_lock(&max_wait_mutex);
if (waitingTime > maxWaitTime)
{
maxWaitTime = waitingTime;
}
pthread_mutex_unlock(&max_wait_mutex);
}
// if landing then 1 if launch 2
int wait_time = (job_type == 1 || job_type == 4) ? 2 : 4;
pthread_sleep(wait_time);
// once job is done:
gettimeofday(¤t_time, NULL);
pthread_mutex_lock(&padA_queue_mutex);
Job done = Dequeue(padA_queue);
char status;
if (job_type == 1) {
status = 'L';
}
else if (job_type == 4){
status = 'E';
}
else {
status = 'D';
}
pthread_mutex_unlock(&padA_queue_mutex);
/*
if (job_type == 2) {
pthread_mutex_lock(&land_counter_mutex);
landCount--;
pthread_mutex_unlock(&land_counter_mutex);
}*/
fprintf(events_log, "%d\t\t%c\t\t%ld\t\t%ld\t\t%ld\t\t%c\n",
done.ID,
status,
done.request_time.tv_sec - start_sc,
current_time.tv_sec - start_sc,
current_time.tv_sec - done.request_time.tv_sec,
'A');
}
else
{
pthread_mutex_unlock(&padA_queue_mutex);
}
gettimeofday(¤t_time, NULL);
}
pthread_exit(NULL);
}
// Pad B thread that controls the actions on pad B
void *PadB(void *arg)
{
// fprintf(events_log,"pad b thread created\n");
struct timeval current_time;
gettimeofday(¤t_time, NULL);
while (current_time.tv_sec < end_sc)
{
// fprintf(events_log,"inside pad b\n");
pthread_mutex_lock(&padB_queue_mutex);
// if there is an job is in pad B than do not need to control until it is done
if (!isEmpty(padB_queue))
{
// pthread_mutex_unlock(&padB_queue_mutex);
int job_type = padB_queue->head->data.type;
pthread_mutex_unlock(&padB_queue_mutex);
if (job_type == 3)
{
struct timeval finishedWaiting;
gettimeofday(&finishedWaiting, NULL);
int waitingTime = finishedWaiting.tv_sec - padB_queue->head->data.request_time.tv_sec;
//printf("Waiting time: %d\n", waitingTime);
pthread_mutex_lock(&max_wait_mutex);
if (waitingTime > maxWaitTime)
{
maxWaitTime = waitingTime;
}
pthread_mutex_unlock(&max_wait_mutex);
}
// if landing or emergency then 1 if assembly then 3
int wait_time = (job_type == 1 || job_type == 4) ? 2 : 12;
pthread_sleep(wait_time);
gettimeofday(¤t_time, NULL);
// once job is done:
pthread_mutex_lock(&padB_queue_mutex);
Job done = Dequeue(padB_queue);
char status;
if (job_type == 1) {
status = 'L';
}
else if (job_type == 4){
status = 'E';
}
else {
status = 'A';
}
pthread_mutex_unlock(&padB_queue_mutex);
/*
if (job_type ==3) {
pthread_mutex_lock(&land_counter_mutex);
landCount--;
pthread_mutex_unlock(&land_counter_mutex);
}*/
fprintf(events_log, "%d\t\t%c\t\t%ld\t\t%ld\t\t%ld\t\t%c\n",
done.ID,
status,
done.request_time.tv_sec - start_time.tv_sec,
current_time.tv_sec - start_time.tv_sec,
current_time.tv_sec - done.request_time.tv_sec,
'B');
}
else
{
pthread_mutex_unlock(&padB_queue_mutex);
// sleep for 2 second since t=2 given there might be a new job generated
}
gettimeofday(¤t_time, NULL);
}
pthread_exit(NULL);
}
// the function that controls the air traffic
void *ControlTower(void *arg)
{
// fprintf(events_log,"inside CT\n");
struct timeval current_time;
gettimeofday(¤t_time, NULL);
// until time is done
while (current_time.tv_sec < end_sc)
{
// fprintf(events_log,"inside CT while\n");
// Check if pad A is busy or not
pthread_mutex_lock(&padA_queue_mutex);
if (isEmpty(padA_queue))
{
// If pad A is not busy, determine which task to assign
pthread_mutex_lock(&a_priority_mutex);
int priority = pad_a_priority;
pthread_mutex_unlock(&a_priority_mutex);
if(priority == 4) {
pthread_mutex_lock(&emergency_queue_mutex);
Job currentJob = Dequeue(emergency_queue);
pthread_mutex_unlock(&emergency_queue_mutex);
Enqueue(padA_queue, currentJob);
pthread_mutex_lock(&prev_a_mutex);
int prev_pri = previous_a_priority;
pthread_mutex_unlock(&prev_a_mutex);
pthread_mutex_lock(&a_priority_mutex);
pad_a_priority = prev_pri;
pthread_mutex_unlock(&a_priority_mutex);
}
else if (priority == 1)
{
// If landing has priority, we should determine if there are any landing jobs available
pthread_mutex_lock(&land_queue_mutex);
if (!isEmpty(land_queue))
{
Job currentJob = Dequeue(land_queue);
pthread_mutex_unlock(&land_queue_mutex);
Enqueue(padA_queue, currentJob);
pthread_mutex_lock(&a_priority_mutex);
pad_a_priority = 2;
pthread_mutex_unlock(&a_priority_mutex);
}
else
{
pthread_mutex_unlock(&land_queue_mutex);
pthread_mutex_unlock(&a_priority_mutex);
pthread_mutex_lock(&launch_queue_mutex);
if (!isEmpty(launch_queue))
{
Job currentJob = Dequeue(launch_queue);
pthread_mutex_unlock(&launch_queue_mutex);
Enqueue(padA_queue, currentJob);
}
else
pthread_mutex_unlock(&launch_queue_mutex);
}
}
else if (priority == 2)
{
pthread_mutex_lock(&launch_queue_mutex);
if (!isEmpty(launch_queue))
{
Job currentJob = Dequeue(launch_queue);
pthread_mutex_unlock(&launch_queue_mutex);
Enqueue(padA_queue, currentJob);
pthread_mutex_lock(&a_priority_mutex);
pad_a_priority = 1;
pthread_mutex_unlock(&a_priority_mutex);
}
else
{
pthread_mutex_unlock(&launch_queue_mutex);
pthread_mutex_unlock(&a_priority_mutex);
pthread_mutex_lock(&land_queue_mutex);
if (!isEmpty(land_queue))
{
Job currentJob = Dequeue(land_queue);
pthread_mutex_unlock(&land_queue_mutex);
Enqueue(padA_queue, currentJob);
}
else
pthread_mutex_unlock(&land_queue_mutex);
}
}
}
pthread_mutex_unlock(&padA_queue_mutex);
pthread_mutex_lock(&padB_queue_mutex);
if (isEmpty(padB_queue))
{
// If pad A is not busy, determine which task to assign
pthread_mutex_lock(&b_priority_mutex);
int priority = pad_b_priority;
pthread_mutex_unlock(&b_priority_mutex);
if(priority == 4) {
pthread_mutex_lock(&emergency_queue_mutex);
Job currentJob = Dequeue(emergency_queue);
pthread_mutex_unlock(&emergency_queue_mutex);
Enqueue(padB_queue, currentJob);
pthread_mutex_lock(&prev_b_mutex);
int prev_pri = previous_b_priority;
pthread_mutex_unlock(&prev_b_mutex);
pthread_mutex_lock(&b_priority_mutex);
pad_b_priority = prev_pri;
pthread_mutex_unlock(&b_priority_mutex);
}
if (priority == 1)
{
// If landing has priority, we should determine if there are any landing jobs available
pthread_mutex_lock(&land_queue_mutex);
if (!isEmpty(land_queue))
{
Job currentJob = Dequeue(land_queue);
pthread_mutex_unlock(&land_queue_mutex);
Enqueue(padB_queue, currentJob);
pthread_mutex_lock(&b_priority_mutex);
pad_b_priority = 3;
pthread_mutex_unlock(&b_priority_mutex);
}
else
{
pthread_mutex_unlock(&land_queue_mutex);
pthread_mutex_unlock(&b_priority_mutex);
pthread_mutex_lock(&assembly_queue_mutex);
if (!isEmpty(assembly_queue))
{
Job currentJob = Dequeue(assembly_queue);
pthread_mutex_unlock(&assembly_queue_mutex);
Enqueue(padB_queue, currentJob);
}
else
pthread_mutex_unlock(&assembly_queue_mutex);
}
}
else if (priority == 3)
{
pthread_mutex_lock(&assembly_queue_mutex);
if (!isEmpty(assembly_queue))
{
Job currentJob = Dequeue(assembly_queue);
pthread_mutex_unlock(&assembly_queue_mutex);
Enqueue(padB_queue, currentJob);
pthread_mutex_lock(&b_priority_mutex);
pad_b_priority = 1;
pthread_mutex_unlock(&b_priority_mutex);
}
else
{
pthread_mutex_unlock(&assembly_queue_mutex);
pthread_mutex_unlock(&b_priority_mutex);
pthread_mutex_lock(&land_queue_mutex);
if (!isEmpty(land_queue))
{
Job currentJob = Dequeue(land_queue);
pthread_mutex_unlock(&land_queue_mutex);
Enqueue(padA_queue, currentJob);
}
else
pthread_mutex_unlock(&land_queue_mutex);
}
}
}
pthread_mutex_unlock(&padB_queue_mutex);
gettimeofday(¤t_time, NULL);
}
//fprintf(events_log, "Maximum waiting time: %d\n", maxWaitTime);
pthread_exit(NULL);
}