【发布时间】:2016-01-22 15:20:18
【问题描述】:
我想创建一个有两个功能的 cpp 程序。
void func(int num){
//Assume there are contents here
}
int main(){
int num;
cin >> num
ap(num);
}
上面的代码在执行时有效。但是我想在一个线程中使用我的函数func(int num)。
thread t1(func);
t1.join;
当我在线程中使用我的 func() 时,in 不再执行。这就是为什么我不能继续编写我的第二个函数的原因。将值传递给函数以便在线程中使用的正确方法是什么?
【问题讨论】:
-
读取文件并显示内容。使用一个线程阅读,另一个线程用于写作。在线程之间共享一个或两个缓冲区。
标签: c++ multithreading function