Concurrent and Parallel Algorithms Assignment - CTEC2910, 2019

Verified

Added on  2022/09/28

|5
|655
|22
Homework Assignment
AI Summary
This assignment solution addresses concurrency and parallel algorithms, focusing on scenarios like a conveyor belt system with a chef producing doughnuts for multiple customers. The solution explores the use of semaphores to prevent race conditions and ensure data integrity in a multi-threaded environment. It examines situations involving multiple producers and consumers, emphasizing the need for synchronization mechanisms to avoid conflicts. The assignment also delves into problems related to miners entering and exiting a shaft, analyzing potential race conditions and safety concerns. The solution discusses the implementation of wait, signal, and swim code to manage access to shared resources, highlighting the importance of locking mechanisms to prevent deadlocks and ensure the correct execution of concurrent processes. The document also touches upon the use of dynamic arrays and the handling of buffer limitations in the context of the doughnut production and delivery scenario, offering insights into the design and implementation of robust concurrent systems.
Document Page
[TYPE THE COMPANY NAME]
2019
[Type the document title]
[Type the document subtitle]
[Type the author name]
[ T Y P E T H E C O M P A N Y A D D R E S S ]
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Table of Contents
Question 1...................................................................................................................................................2
Question a)..............................................................................................................................................2
Question b)..............................................................................................................................................2
Question 2...................................................................................................................................................3
a).............................................................................................................................................................3
i)...........................................................................................................................................................3
ii)..........................................................................................................................................................3
b).............................................................................................................................................................3
i)...........................................................................................................................................................3
ii)..........................................................................................................................................................4
2 | P a g e
Document Page
Question 1
Question a)
In this assignment we have studied the situation of the conveyor belt also the place where a chef do the
production of the doughnut and then put it on the conveyor belt.
When the belt limit is full then it releases for the delivery of the customers. Now we have to study for
one chef with multiple customers. Before the processing the buffer is fixed and in this condition, we
have considered infinite buffer. If we do not change the fixed buffer to infinite then it will show buffer
index error. We also need to fix the doughnut quantity and we need to develop the dynamic array when
there are multiple customers the first thing we need to do is use of the semaphore with a locking
system so when the chief is producing no other process will enter into the buffer.
Question b)
Here, the problem is a single customer with multiple producers and multiple producer thread will call
the method of the populate map. Another we can use the single thread of the single customer. Here our
customers read the data from the map or conveyer belt. Here, we will be using multiple channels with
the parallel process. But when we run the multiple channels in the parallel way then there will be the
possibility of race condition. There will be no need of block in the program or code. If the conveyer belt
is empty then it will be returned start and back in 30 seconds.
3 | P a g e
Document Page
Question 2
a)
i)
As per the situation, we have seen the use of wait, swim and signal code. If there are 5 miners in the
shaft and one leaves them, there will be no race and safety conditions that will arise. As per the given
situation, 5 people can be entered into the mine. The miner code which we had given is ok for the
situation and no need to change the condition. No need to add a locking condition but it is good if add
semaphore. So less than five people will be ok and no risk will occur in the execution.
ii)
In another situation, we have to see that if there will be 5 people already in the shaft & another try to
enter into the shaft. Then, it will arise the race and safety condition which we be possible to create
deadlock situations also. It will cause the series issue and may be possible to create the death condition.
We can do one the if we set the mine=2 then set the locking then it will be a possibility to avoid the race
the condition.
4 | P a g e
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
b)
i) Here, we know that the variable totalentered will be increment by one but it is showing that how
many number of persons go for the swim and it does not reflect how many people are swimming
presently. It will cause the race death condition.
ii)
wait(S1) {
while(S1<=0); {P S1--;}
signal(S1) { S1++;}
Here, we have seen that condition will show trace demonstration .
5 | P a g e
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]