Pthread_setaffinity_np 无效参数

发布于 2024-12-27 11:21:47 字数 452 浏览 3 评论 0原文

我正在尝试更改启动例程内每个线程的亲和力。

这是代码。在下面的代码中,“t”是通过 pthread_create 函数传递的参数。

    cpu_set_t mask;
    pthread_t c;

    a = *((int *)t);

    printf(" thread no. is %d \n",a);

    CPU_ZERO(&mask);

    a =a/2 + 1;

    CPU_SET(a,&mask);

    c=pthread_self();
    s=pthread_setaffinity_np(c,sizeof(cpu_set_t), &mask);
    if (s!=0)
        handle_error_en(s,"pthread_setaffinity_np");

线程关联性没有改变。我哪里出错了?

I am trying to change the affinity of each thread inside the start routine.

Here's the code. In the below code, 't' is the argument passed through the pthread_create function.

    cpu_set_t mask;
    pthread_t c;

    a = *((int *)t);

    printf(" thread no. is %d \n",a);

    CPU_ZERO(&mask);

    a =a/2 + 1;

    CPU_SET(a,&mask);

    c=pthread_self();
    s=pthread_setaffinity_np(c,sizeof(cpu_set_t), &mask);
    if (s!=0)
        handle_error_en(s,"pthread_setaffinity_np");

The thread affinity is not getting changed. Where am I going wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓦然回首 2025-01-03 11:21:47

我误解了面具的界限。那就是我出错的地方。

I had misunderstood the bounds of the mask. That was where I was going wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文