Computers and Technology

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
}

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 04:10, cvbnkifdfg
2pointswho was mikhail gorbachev? oa. a russian leader who opposed a coupob. a polish leader who founded the labor union "solidarityoc. a soviet leader who called for a closer relationship with the unitedstates, economic reform, and a more open societyd. a soviet leader who called for more oppression in the soviet union
Answers: 3
image
Computers and Technology, 23.06.2019 18:40, cyn95xx
Johnson enterprises uses a computer to handle its sales invoices. lately, business has been so good that it takes an extra 3 hours per night, plus every third saturday, to keep up with the volume of sales invoices. management is considering updating its computer with a faster model that would eliminate all of the overtime processing.
Answers: 2
image
Computers and Technology, 23.06.2019 19:30, carcon2019
Amitha writes up a one-page summary of a novel during her summer internship at a publishing company. when she reads over the page, she realizes she used the word “foreshadow” seven times, and she would like to reduce the repetition. which tool would best amitha solve this problem?
Answers: 3
image
Computers and Technology, 24.06.2019 00:30, bsonicx
The best definition of an idiom is a. a word or phrase that describes a noun b. a word or phrase describing a verb c. a phrase containing figurative language in which the word expresses a different idea from its exact meaning d. a phrase that compares two unlike objects or ideas
Answers: 2
Do you know the correct answer?
Now, we continue from Question 4 above. Before making his final decision on whether to use multi-thr...

Questions in other subjects:

Konu
Social Studies, 03.05.2021 23:00