Description
a) WORKING SECTIONS: As far as I have been able to identify, all sections of my code are working as intended. There is a small chance that I misinterpreted the instructions regarding one or more of the implementation guidelines.
b) Show the following:
i) The logic used to identify the terminating condition: I have my consumers sleeping for .1 seconds at the start of the looping, so the producers can add at least something to the Print Queue, so I knew the exit condition would be dependent on the value stored in the counting semaphore referred to as empty_sem. Further testing revealed that in the case that there are more consumers than producers, simply checking the value of empty_sem isnโt enough since the consumers can hit the check and exit before the producers finish, so I put a counter in shared memory to keep track of open processes in order to determine when the processes concluded. Combining the checks for no open processes and a 0 in empty_sem, we arrive at a robust exit condition. ii) How were the semaphores and other book-keeping variables shared between processes and threads: The semaphores and bookkeeping variables were shared between processes and threads by initializing the semaphores using a _pthreadshared flag of 1, and globally declaring the variables in addition to putting variables into shared memory.
iii) What was done in the signal handler for graceful termination: I consistently encountered seg-faults when calling my detaching, so I found that I needed to ensure that only one process was reaching the detach and ctl statements, so i stored the pid of the main process and then checked in the signal handler if the current pid was equal to the main pid. I then tried using my SIGINT handler, but multiple processes continued printing, so i locked the binary semaphore to ensure that only the signal handler had access to printing, and no other processes could access stdout. I then canceled the threads first, and then killed the processes by using kill. Kill takes a pid, so i stored the pids in a shared memory array, and sequentially call kill on them. I then called the detaching and clearing on the shared memory, followed by an exit of the program.
iv) How did the LIFO and FIFO implementations differ in terms of your usage of either the buffer_index variable or in/out pointers: I used the buffer index in shared memory in the LIFO implementation since the locations are always adjacent, and I used in/out pointers in shared memory in order to keep track of the location of the left-most element.
c) SHOW 2 RUNS OF YOUR CODE (COPY/PASTE):
LIFO: 3p, 4c
Producer 63084 added 437 to buffer
Consumer 0 dequeue 63084, 437 bytes from buffer
Producer 63082 added 337 to buffer
Consumer 1 dequeue 63082, 337 bytes from buffer
Producer 63084 added 288 to buffer
Consumer 2 dequeue 63084, 288 bytes from buffer
Producer 63083 added 772 to buffer
Consumer 3 dequeue 63083, 772 bytes from buffer
Producer 63082 added 337 to buffer
Consumer 0 dequeue 63082, 337 bytes from buffer
Producer 63084 added 288 to buffer
Consumer 1 dequeue 63084, 288 bytes from buffer
Producer 63082 added 234 to buffer
Consumer 2 dequeue 63082, 234 bytes from buffer
Producer 63082 added 234 to buffer
Consumer 3 dequeue 63082, 234 bytes from buffer
Producer 63084 added 274 to buffer
Consumer 0 dequeue 63084, 274 bytes from buffer
Producer 63084 added 585 to buffer
Consumer 1 dequeue 63084, 585 bytes from buffer
Producer 63082 added 225 to buffer
Consumer 2 dequeue 63082, 225 bytes from buffer
Producer 63084 added 585 to buffer
Consumer 3 dequeue 63084, 585 bytes from buffer
Producer 63082 added 974 to buffer
Consumer 0 dequeue 63082, 974 bytes from buffer
Producer 63084 added 561 to buffer
Consumer 1 dequeue 63084, 561 bytes from buffer
Producer 63082 added 564 to buffer
Consumer 2 dequeue 63082, 564 bytes from buffer
Producer 63084 added 556 to buffer
Consumer 3 dequeue 63084, 556 bytes from buffer
Producer 63082 added 564 to buffer
Consumer 0 dequeue 63082, 564 bytes from buffer
Producer 63084 added 556 to buffer
Consumer 1 dequeue 63084, 556 bytes from buffer
Producer 63082 added 416 to buffer
Consumer 2 dequeue 63082, 416 bytes from buffer
Producer 63084 added 542 to buffer
Consumer 3 dequeue 63084, 542 bytes from buffer
Producer 63082 added 416 to buffer
Consumer 0 dequeue 63082, 416 bytes from buffer
Producer 63084 added 666 to buffer
Consumer 1 dequeue 63084, 666 bytes from buffer
Producer 63082 added 873 to buffer
Consumer 2 dequeue 63082, 873 bytes from buffer
Producer 63084 added 666 to buffer Consumer 3 dequeue 63084, 666 bytes from buffer number of jobs produced: 24 Number of bytes produced: 11950
number of jobs consumed: 24 Number of bytes consumed: 11950
FIFO 3p, 4c:
Producer 80346 added 855 to buffer
Consumer 1 dequeue 80346, 855 bytes from buffer Producer 80344 added 107 to buffer
Consumer 0 dequeue 80344, 107 bytes from buffer
Producer 80346 added 855 to buffer
Consumer 2 dequeue 80346, 855 bytes from buffer
Producer 80344 added 107 to buffer
Consumer 3 dequeue 80344, 107 bytes from buffer
Producer 80346 added 855 to buffer
Consumer 1 dequeue 80346, 855 bytes from buffer
Producer 80344 added 107 to buffer
Consumer 0 dequeue 80344, 107 bytes from buffer
Producer 80346 added 855 to buffer
Consumer 2 dequeue 80346, 855 bytes from buffer
Producer 80344 added 107 to buffer
Consumer 3 dequeue 80344, 107 bytes from buffer
Producer 80346 added 855 to buffer
Consumer 1 dequeue 80346, 855 bytes from buffer
Producer 80345 added 891 to buffer
Producer 80344 added 107 to buffer
Consumer 0 dequeue 80345, 891 bytes from buffer
Consumer 2 dequeue 80344, 107 bytes from buffer
Producer 80346 added 855 to buffer
Consumer 3 dequeue 80346, 855 bytes from buffer
Producer 80344 added 485 to buffer
Consumer 1 dequeue 80344, 485 bytes from buffer
Producer 80346 added 861 to buffer
Consumer 0 dequeue 80346, 861 bytes from buffer
Producer 80346 added 861 to buffer
Consumer 2 dequeue 80346, 861 bytes from buffer
Producer 80345 added 653 to buffer
Consumer 3 dequeue 80345, 653 bytes from buffer
Producer 80346 added 861 to buffer
Consumer 1 dequeue 80346, 861 bytes from buffer
Producer 80345 added 653 to buffer
Consumer 0 dequeue 80345, 653 bytes from buffer
Producer 80344 added 485 to buffer
Consumer 2 dequeue 80344, 485 bytes from buffer
Producer 80346 added 216 to buffer
Consumer 3 dequeue 80346, 216 bytes from buffer
Producer 80345 added 634 to buffer
Consumer 1 dequeue 80345, 634 bytes from buffer Producer 80346 added 216 to buffer
Consumer 0 dequeue 80346, 216 bytes from buffer Producer 80344 added 293 to buffer
Consumer 2 dequeue 80344, 293 bytes from buffer
Producer 80345 added 505 to buffer
Consumer 3 dequeue 80345, 505 bytes from buffer
Producer 80345 added 505 to buffer
Consumer 1 dequeue 80345, 505 bytes from buffer
Producer 80345 added 505 to buffer
Consumer 0 dequeue 80345, 505 bytes from buffer
Producer 80344 added 663 to buffer
Consumer 2 dequeue 80344, 663 bytes from buffer
Producer 80345 added 505 to buffer
Consumer 3 dequeue 80345, 505 bytes from buffer
Producer 80346 added 432 to buffer
Consumer 1 dequeue 80346, 432 bytes from buffer
Producer 80345 added 505 to buffer
Consumer 0 dequeue 80345, 505 bytes from buffer
Producer 80345 added 505 to buffer
Consumer 2 dequeue 80345, 505 bytes from buffer
Producer 80346 added 432 to buffer
Consumer 3 dequeue 80346, 432 bytes from buffer
Producer 80345 added 505 to buffer
Consumer 1 dequeue 80345, 505 bytes from buffer
Producer 80344 added 663 to buffer
Consumer 0 dequeue 80344, 663 bytes from buffer
Producer 80345 added 505 to buffer
Consumer 2 dequeue 80345, 505 bytes from buffer
Producer 80346 added 432 to buffer
Consumer 3 dequeue 80346, 432 bytes from buffer
Producer 80345 added 505 to buffer
Consumer 1 dequeue 80345, 505 bytes from buffer
Producer 80345 added 505 to buffer
Consumer 0 dequeue 80345, 505 bytes from buffer
Producer 80345 added 724 to buffer
Consumer 2 dequeue 80345, 724 bytes from buffer
Producer 80346 added 156 to buffer
Consumer 3 dequeue 80346, 156 bytes from buffer
Producer 80346 added 156 to buffer
Consumer 1 dequeue 80346, 156 bytes from buffer
Producer 80345 added 724 to buffer
Consumer 0 dequeue 80345, 724 bytes from buffer
Producer 80346 added 689 to buffer
Consumer 2 dequeue 80346, 689 bytes from buffer
Producer 80345 added 121 to buffer
Consumer 3 dequeue 80345, 121 bytes from buffer
Producer 80345 added 121 to buffer
Consumer 1 dequeue 80345, 121 bytes from buffer
Producer 80345 added 121 to buffer
Consumer 0 dequeue 80345, 121 bytes from buffer
Producer 80346 added 689 to buffer
Consumer 2 dequeue 80346, 689 bytes from buffer
Producer 80345 added 121 to buffer
Consumer 3 dequeue 80345, 121 bytes from buffer
Producer 80345 added 433 to buffer
Consumer 1 dequeue 80345, 433 bytes from buffer
Producer 80346 added 920 to buffer
Consumer 0 dequeue 80346, 920 bytes from buffer
Producer 80345 added 433 to buffer
Consumer 2 dequeue 80345, 433 bytes from buffer
Producer 80346 added 295 to buffer
Consumer 3 dequeue 80346, 295 bytes from buffer
Producer 80345 added 679 to buffer
Consumer 1 dequeue 80345, 679 bytes from buffer
Producer 80346 added 295 to buffer
Consumer 0 dequeue 80346, 295 bytes from buffer
Producer 80345 added 679 to buffer
Consumer 2 dequeue 80345, 679 bytes from buffer
Producer 80346 added 683 to buffer
Consumer 3 dequeue 80346, 683 bytes from buffer
Producer 80345 added 448 to buffer
Consumer 1 dequeue 80345, 448 bytes from buffer
Producer 80346 added 683 to buffer
Consumer 0 dequeue 80346, 683 bytes from buffer
Producer 80346 added 127 to buffer
Consumer 2 dequeue 80346, 127 bytes from buffer
Producer 80345 added 247 to buffer
Consumer 3 dequeue 80345, 247 bytes from buffer
Producer 80346 added 119 to buffer
Consumer 1 dequeue 80346, 119 bytes from buffer
Producer 80346 added 337 to buffer
Consumer 0 dequeue 80346, 337 bytes from buffer
Producer 80346 added 337 to buffer
Consumer 2 dequeue 80346, 337 bytes from buffer
Producer 80346 added 345 to buffer
Consumer 3 dequeue 80346, 345 bytes from buffer
Producer 80346 added 345 to buffer
Consumer 1 dequeue 80346, 345 bytes from buffer
Producer 80346 added 260 to buffer
Consumer 0 dequeue 80346, 260 bytes from buffer
number of jobs produced: 66 Number of bytes produced: 31733 number of jobs consumed: 66 Number of bytes consumed: 31733
d) EXECUTION TIME / AVG WAITING TIME **ALL FLOATS ARE IN SECONDS**
FIRST TABLE: LIFO
Num of producers
Num of consumers 2 4 6 8 10
2 6.384797406
/
2.679813670 11.74418881
9 /
4.590448102 12.34428842
0 /
5.066584436 11.98070640
9 /
5.131895167 15.68372343
9 /
6.424601099
4 9.941738823
/
4.579125385 12.27622942
6 /
5.320818532 12.15702348
7 /
5.625400208 13.71704602
8 /
4.423992015 18.44409257
9 /
5.312744111
6 3.093523524
/
1.724750124 5.746394063
/
2.422272174 11.83095288
8 /
4.460758612 13.57915705
3 /
4.436558150 14.81661958
3 /
4.998571024
8 13.12899724
2 /
6.773245819 13.58637020
9 /
4.575693229 8.795305467
/
3.160491775 11.29186116
6 /
4.039133408 12.48460146
6 /
4.423926341
10 10.52522535
6 /
5.441957080 8.463019325
/
2.863113136 12.41917296
0 /
5.061312580 13.04105555
9 /
4.915921031 11.14485044
9 /
4.882928592
SECOND TABLE: FIFO
Num of producers
Num of consumers 2 4 6 8 10
2 10.53623287
3 /
4.843307570 13.05248664
9 /
4.723566180 14.87079484
5 /
5.725485959 16.11519257
4 /
5.366771861 12.61787179
8 /
4.727259716
4 8.625568751
/
3.756156774 11.73534263
9 /
3.524932648 12.75803567
8 /
5.075448000 13.11573024
5 /
4.589308600 16.79541199
8 /
5.574982545
6 5.076154332
/
2.577705889 12.56987256
0 /
4.195156254 13.10369573
6 /
4.886703696 11.26591142
6 /
4.597888708 12.72430896
7 /
4.626259746
8 7.927996184
/
3.635638136 10.45967718
7 /
4.202647503 15.97908482
0 /
5.431967366 14.80017811
7 /
5.593091630 12.30596030
4 /
4.647454186
10 12.41729926
4 /
5.124528809 16.14821342
1 /
6.185665620 11.53984496
4 /
5.161250275 10.82905939
1 /
3.681134264 13.38004224
6 /
5.139326224
Reviews
There are no reviews yet.