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 21:40
Develop a function to create a document in the mongodb database “city” in the collection “inspections.” be sure it can handle error conditions gracefully. a. input -> argument to function will be set of key/value pairs in the data type acceptable to the mongodb driver insert api call b. return -> true if successful insert else false (require a screenshot)
Answers: 2
question
Computers and Technology, 23.06.2019 09:30
Write an essay on online collaboration, how to do it, the challenges, resolving the challenges, and consider whether the risks are greater than rewards. ( need )
Answers: 1
question
Computers and Technology, 23.06.2019 15:30
Hey so i was just trying out some game hacks so i took a paste from online and built it in my visual studio and then suddenly my computer was working or clicking on stuff on its own am i hacked?
Answers: 1
question
Computers and Technology, 23.06.2019 22:30
You draw two cards from a standard deck of 52 cards, but before you draw the second card, you put the first one back and reshuffle the deck. (a) are the outcomes on the two cards independent? why?
Answers: 3
You know the right answer?
Now, we continue from Question 4 above. Before making his final decision on whether to use multi-thr...
Questions
question
Mathematics, 19.05.2021 23:00
question
Mathematics, 19.05.2021 23:00
question
Mathematics, 19.05.2021 23:00
question
Mathematics, 19.05.2021 23:00
question
English, 19.05.2021 23:00
Questions on the website: 13722361