Question
Code a program to create N worker threads by the main thread. Program K quantity A shareable search tree with a number of nodes must
Code a program to create N worker threads by the main thread. Program K quantity A shareable search tree with a number of nodes must contain (defined as a global variable). This tree will be shared among all threads. It will be implemented with the help of web pointers. You cannot use arrays. The tree will keep the largest K values up to now in the input files. Each worker thread can only process one file (1 integer value per line. it will be). There will be N input files. Each worker thread can save only one file at a time. It can read integer values. This time you can read with fscanf (easier). Input file After reading the values from the worker threads, if the conditions are met, the value will be added to the tree. If not, the integer value will be left and the other integer value in the file will be taken. All N workers this way the threads will run simultaneously. When all worker threads have finished N files We will see the largest K integer values contained in it on the tree. Then the main thread runs these values. will write to the output file in an orderly descending order. You will create the tree yourself. Any You cannot use library or canned code. The program will be run as part1 K N infile1 ... infileN outfile. If you need to synchronize threads, you can use POSIX mutex and state variables. You should use worker processes to process t input files. You will also use shared memory to share information between parent and child processes. This means that to use shared memory, you must implement the data structure. The shared memory must be big enough. Structure binary search tree or a heap or a simple array may be. Up to you. But regardless of the structure, the input files are the most it will hold large K values. This means that the content of the shared data structure is It must change dynamically as it is being processed by the child process. Integer values are shared You cannot store it anywhere except memory (like 1 array for each child process.) Program part2 K N infile1 ... infileN outfile
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