加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux-kernel – SMP linux内核中的障碍

发布时间:2020-12-14 00:02:48 所属栏目:Linux 来源:网络整理
导读:在SMP Linux内核中是否存在类似pthread_barrier的问题? 当内核同时在2个或更多具有相同结构的CPU上工作时,屏障(如pthread_barrier)可能很有用.它将阻止所有CPU进入它,直到最后一个CPU运行屏障.从这时起,所有CPU都会再次运行. 解决方法 您可以使用完成获得等
在SMP Linux内核中是否存在类似pthread_barrier的问题?

当内核同时在2个或更多具有相同结构的CPU上工作时,屏障(如pthread_barrier)可能很有用.它将阻止所有CPU进入它,直到最后一个CPU运行屏障.从这时起,所有CPU都会再次运行.

解决方法

您可以使用完成获得等效行为:

struct fake_barrier_t {
  atomic_t count;
  struct completion comp;
}

/* run before each pass */
void initialize_fake_barrier(struct fake_barrier_t* b)
{
  atomic_set(&b->count,0);
  init_completion(&b->comp);
}

/* make all tasks sleep until nth arrives,then wake all. */
void fake_barrier(struct fake_barrier_t* b,int n)
{
  if (atomic_inc_return(&b->count) < n)
    wait_for_completion(&b->comp);
  else
    complete_all(&b->comp);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读