小编Tai*_*Kai的帖子

pthread 只有在线程数很少时才能正常工作

我正在尝试逐个像素地加密 BMP 图像,并且我使用 pthread 并行加密它们。

我的代码有点像这样:

struct arg_struct {
    int arg1;
    int arg2;
    ...
};

void* print_message(void* arguments) {
    struct arg_struct* args = (struct arg_struct*)arguments;

    //Encryption...

    // exit from current thread
    pthread_exit(NULL);
}

void multiThreadExample() {
    cout << "Start..." << endl;
    const int NUMBER_OF_THREADS = 50000; // number of pixels
    pthread_t thread[NUMBER_OF_THREADS];
    arg_struct arg[NUMBER_OF_THREADS];
    for (int i=0;i<NUMBER_OF_THREADS;i++) {
        arg[i].arg1 = i;
        arg[i].arg2 = ... // give values to arguments in arg_struct
        pthread_create(&thread[i], NULL, print_message, static_cast<void*>(&arg[i]));
    }

    for(int i = 0; …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading pthreads

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

标签 统计

c++ ×1

multithreading ×1

pthreads ×1