Design a multi-threaded program using Pthreads to implement parallel text search. The specific requirements are as follows:

You need to implement a function that accepts a target string and a folder path containing multiple text files. The program should search each text file in parallel, find the lines that contain the target string, and print the matching lines.

Each thread should process a file, and you need to allocate files to different threads reasonably.

Ensure that your program is thread-safe and properly handles synchronization issues between multiple threads.

Provide a test case that includes multiple text files and a target string to verify the correctness and performance of your program

设计一个多线程程序使用Pthreads来实现并行文本搜索。具体要求如下:你需要实现一个函数该函数接受一个目标字符串和一个包含多个文本文件的文件夹路径。程序应该并行地搜索每个文本文件查找包含目标字符串的行并将匹配的行打印出来。每个线程应该处理一个文件你需要合理地分配文件给不同的线程。确保你的程序是线程安全的并正确处理多个线程之间的同步问题。提供一个测试用例包含多个文本文件和一个目标字符串以验证你的程

原文地址: http://www.cveoy.top/t/topic/fESt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录