subject

Now, we continue from Question 4 above. Before making his final decision on whether to use multi-threading or single-threading, the team leader asked you to show him a demonstration about how the multiple threads will be synchronized (so we completely ignore anything related to Round-Robin scheduling or time quantum here). You decided to implement 4 threads and divide the array into 4 sections. Thread T1 searches the first quarter (index 0 to 2,249,999), thread T2 searches the second quarter (index 2,500,000 to 4,999,999), thread T3 searches the third quarter (index 5,000,000 to 7,499,999) and thread T4 searches the last quarter (index 7,500,000 to 9,999,999. Thus, every thread knows its quarter and runs independently from the other threads.
When a thread T1...T4 has finished searching its quarter, successfully or unsuccessfully, it sets its state to finish using the boolean array finishRequest[i], where i = 1,...,4, and waits until the application, through its main thread T0, sends it a signal to terminate. However, if the search is successful, then this tread must inform all other threads immediately, and so the other threads consequently just terminate their searches, set their state to finish, using the boolean array finishRequest[i], and wait for a signal from the main thread, T0, to terminate. Once all 4 threads have terminated, the main thread, T0, can finally terminate.
Using Semaphores or Monitors, Write the synchronization code (You are NOT required to (and should not) write actual Java code for the solution; rather you need to write the solution using semaphore/monitor pseudo-code notation, and structures such as if, while, ... if necessary). In particular, you need to write the code for thread To and for threads T1, T2, T3 and T4. Use the following data structures and layouts for T0 and T1... T4 as given below.

→ It is better that you write the code of Ti...T4 using one single method that takes the thread ID as a parameter. However, if you wish, you are allowed to give the code of these 4 threads separately as well (i. e., in that case you will give the code of 5 different methods for each of the 5 threads).
// Shared data structures, you need to add other constructs as needed
// Initialize the state of all threads to not finished.
// A thread TT4 sets finishRequest[i] to true when it needs to terminate.
boolean finishRequest[n] = {false}; // All initialized to false here

T(0)
{
... // This is what you need to fill for T, code
}
T(int tid ) // tid is 1...4
{
... // This is what you need to fill for T, to T code
...// Again, if you wish, you can write 4 separate methods; one for each of the 4 threads
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 04:30
Eye injuries usually occur as a result of all of the following things, except: a) proper machine operation b) battery explosion c) falling or flying debris d) electric welding arc
Answers: 2
question
Computers and Technology, 23.06.2019 02:30
What is the power dissipated by a resistor with a current of 0.02 a and a resistance of 1,000 ? a. 200 w b. 20 w c. 0.4 w d. 4 w
Answers: 1
question
Computers and Technology, 23.06.2019 17:00
1. which of the following is not an example of an objective question? a. multiple choice. b. essay. c. true/false. d. matching 2. why is it important to recognize the key word in the essay question? a. it will provide the answer to the essay. b. it will show you a friend's answer. c. it will provide you time to look for the answer. d. it will guide you on which kind of answer is required.
Answers: 1
question
Computers and Technology, 23.06.2019 20:40
On nba 2k 19, every time i try to join a my park game, it leads ro a website telling my dad that he needs ps plus. i already have ps plus though. how do i fix this?
Answers: 2
You know the right answer?
Now, we continue from Question 4 above. Before making his final decision on whether to use multi-thr...
Questions
Questions on the website: 13722363