好的我正试图传递一对数字struct来pthread_create运行pthread.但是我传递的数字和调用函数时得到的数字是不同且随机的
这里是 struct
struct Pairs {
long i,j;
};
Run Code Online (Sandbox Code Playgroud)
内部主要
void main()
{
long thread_cmp_count = (long)n*(n-1)/2;
long t,index = 0;
struct Pairs *pair;
pair = malloc(sizeof(struct Pairs));
cmp_thread = malloc(thread_cmp_count*sizeof(pthread_t));
for(thread = 0;(thread < thread_cmp_count); thread++){
for(t = thread+1; t < n; t++){
(*pair).i = thread;
(*pair).j = t;
pthread_create(&cmp_thread[index++], NULL, Compare, (void*) pair);
}
}
for(thread= 0;(thread<thread_cmp_count); thread++){
pthread_join(cmp_thread[thread], NULL);
}
free(cmp_thread);
}
Run Code Online (Sandbox Code Playgroud)
和功能比较
void* Compare(void* pair){
struct Pairs *my_pair = (struct …Run Code Online (Sandbox Code Playgroud) 在经过初始化之后,我经历了一种奇怪的行为
#include <iostream>
#include <opencv2/opencv.hpp>
int main() {
cv::Mat h = cv::Mat(2, 2, CV_32F, {1.0, 2.0, 1.0, 0.0});
std::cout << h << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
cout打印出来[1,1; 1,1].WTF刚刚发生?我在ubuntu上使用eclipse,gcc版本5.4,OpenCV 3.2
我有一个包含6291456个数字的.txt文件,没有别的.在读完所有内容并push_back进入向量后,该vector.size()函数返回6291457.这个附加元素来自何处?
int disparity;
ifstream disparity_txt;
disparity_txt.open(path);
while(!disparity_txt.eof())
{
disparity_txt >> disparity;
vec_disparities.push_back(disparity);
}
cout << vec_disparities.size() << endl;
disparity_txt.close();
Run Code Online (Sandbox Code Playgroud)