Question: How would you Implement a multi-threaded linear search using c++ The parent process shall load a file of strings into an array (or a vector),

How would you Implement a multi-threaded linear search using c++

The parent process shall load a file of strings into an array (or a vector), split the array into n sections, and then create n number of threads. Each child thread shall search one of the n sections of the array, for the specified string. If the thread does find the string, it records a number of occurrences. The main threads, meanwhile, executes the threads join function. After all threads complete their search, then the main thread prints "string has been found by N threads, there are O occurrences for the sub-string where N is a number of threads that found the string and O is a number of times that sub-string is present in the selected string.

The program shall be ran using the following command line:

./multi-threaded <.txt file> <# of threads >

You may create your test file random.txt with random words.

The textfile example: opp, cdf, xyz, abc, xyz, opp, abc, xyz,xyz

Command line: words.txt, xyz, 4

The output example: The abc string has been found by 3 threads, there are 4 occurrences for the sub-string.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!