小编YuZ*_*YuZ的帖子

将struct作为参数传递给pthread

好的我正试图传递一对数字structpthread_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)

c multithreading struct pthreads

6
推荐指数
1
解决办法
4万
查看次数

cv ::使用数组进行Mat初始化

在经过初始化之后,我经历了一种奇怪的行为

#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

c++ arrays opencv mat

1
推荐指数
1
解决办法
1480
查看次数

从ifstream文件读取错误的大小

我有一个包含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)

c++ stl vector ifstream

0
推荐指数
1
解决办法
250
查看次数

标签 统计

c++ ×2

arrays ×1

c ×1

ifstream ×1

mat ×1

multithreading ×1

opencv ×1

pthreads ×1

stl ×1

struct ×1

vector ×1