我想多个阵列传递到正在使用的std ::线程如下创建的线程:传递数组线程
threadPool.push_back(std::thread(factor, Ap, Ai, Ax, b, Rs, Q, P, Pinv, n, 0, n, scale, nz));
和功能因子定义如下:
void factor(int Ap[], int Ai[], double Ax[], double b[], double *Rs, int *Q, int *P, int *Pinv, int n, int k1, int k2, int scale, int nz);
线程已成功创建,我可以在Visual Studio线程窗口(从调试器)看到它。但是,线程中数组的数据与发送给线程的数据不相似。 任何人有任何想法可能是什么原因?
听起来就像你传递了一个指向函数作用域数组的指针(实质上是一个数组参数),然后退出该函数,以便数组超出范围并被销毁。 – Sneftel 2015-04-03 13:38:34
是的,参数(Ap,Ai,Ax和b)最初定义为指针,然后作为数组传递给函数因子。你能否请进一步解释你的上述评论。 – Anas 2015-04-03 13:42:21
使用相同的解决方案http://stackoverflow.com/questions/4264304/how-to-return-an-array-from-a-method – Sneftel 2015-04-03 13:43:24