Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program to accept an array of 20 elements and a number to search in the main function, both array and the search-number should
Write a program to accept an array of 20 elements and a number to search in the main function, both array and the search-number should be global variables. Write a thread function to search and count the occurrence of the given number. Give a sleep (4) inside the loop in the thread function to model a big process working. Call 5 thread function to do search in 5 separate sections of the array. After calling all function join all threads together and in main function display the occurrence of the number in that array. If there is a race condition identify and synchronize to get the correct output.|| Let the array be 1 3 4 1 5 6 2 7 1 8 9 1 2 3 1 3 1 4 6 7 And let the number to search is 1. Divide the array into 5 and call the same thread function to count the occurrence of 1 in that section. 1 3 4 1 5 6 2 7 1 8 9 1 2 3 1 3 1 4 6 7 2 O 2 1 In main the output will be 6 1's in the array. To Do List Defining variables: 10 points Properly calling thread functions -10 points Thread function -20 points Sleep () called-5 points Synchronized- 25 points
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started