gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 10:14:31 24 4
gpt4 key购买 nike

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);
}

关于linux-kernel - SMP linux 内核中的障碍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2564782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com