将原子变量传递给函数
Passing an atomic variable to a function
我正试图将一个原子变量传递给一个函数,如下所示:
// function factor receives an atomic variable
void factor(std::atomic<int> ThreadsCounter)
{
.........
}
// main starts here
int main()
{
// Atomic variable declaration
std::atomic<int> ThreadsCounter(0);
// passing atomic variable to the function factor through a thread
Threadlist[0] = std::thread (factor, std::ref(ThreadsCounter));
Threadlist[0].join();
return 0;
}
当运行上面的代码时,我得到了以下错误:
错误2错误C2280:"std::atomic::atoic(const std::原子&)":试图引用已删除的函数c:\program files(x86)\microsoft visual studio 12.0\vc\include\functional 1149 1 klu_actor
有人知道怎么解决这个问题吗?非常感谢你的帮助。
函数factor
按值取其ThreadsCounter
参数,而std::atomic
不可复制构造。
即使您绑定了对线程函数的引用,它也试图创建一个副本来传递函数。
相关文章:
- 未使用的C++未优化的静态成员函数/变量
- 内联函数/变量的外部链接
- 同一函数中的静态函数变量初始化顺序
- 将非静态成员函数C 的使用无效,而将成员功能作为函数变量
- 如何从doxygen输出中排除类的无证件成员函数/变量
- 如何在LUA C API中分配全局LUA函数变量
- 如何将函数变量传递给C lambda函数
- 通过另一个C++函数更改函数变量
- c++11 lambda 真的支持闭包吗?函数变量中存在语义冲突
- C++:静态成员不能在声明时定义,但静态函数变量可以?
- apache-frift是否支持函数变量作为参数
- 类函数/变量在使用之前必须声明
- 函数变量去哪里
- 无法使用函数变量?错误表达式必须具有类类型
- 如何在main中使用函数变量
- 每当尝试打印函数变量时,C++ cout 错误
- 是否存在查看成员函数/变量的整洁等效项
- 访问友元类之间的函数变量
- 函数到函数变量
- 一个定义规则是否强制创建一个静态函数变量