接上文和上上文:
要求:
应用程序可以以多线程的方式使用上述API。
保证多线程下,表,索引文件的一致性。
方法:
使用#include <mutex>的互斥锁,保证同时最多只有一个线程打开某文件。用法:
mutex data_lock;
mutex index_lock;
//互斥锁
data_lock.lock();
/**使用表**/
//解开互斥锁
data_lock.unlock();
#include <thread>使用多线程。用法:
void PrintFinded(int property_num, int64_t min, int64_t max){
//用前面的API找数据
return ;
}
int main(){
thread thread1(PrintFinded, 2, 50, 100);
thread thread2(PrintFinded, 2, 50, 100);
thread1.join();
thread2.join();
return 0;
}
就这个意思。接着是测试:
完结。