gpt4 book ai didi

c++ - 在多线程程序中实现动态屏障的可能方法

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:41:54 27 4
gpt4 key购买 nike

我在一篇论文中读到这个...

Consequently, our tool only checkpoints a thread when it is executing at a known safe point: kernel entry, kernel exit, or certain interruptible sleeps in the kernel that we have determined to be safe. The thread that initiates a multithreaded fork creates a barrier on which it waits until all other threads reach a safe point. Once all threads reach the barrier, the original thread creates the checkpoint, then lets the other threads continue execution.

现在我的问题是,有人能猜出作者在谈论什么样的障碍吗?线程如何创建屏障并将屏障动态插入到其他线程中?任何工作示例将不胜感激。

已编辑

请不要说使用 pthread_barrier_wait,因为这不是问题所在。显然,作者有一个线程可以动态地将障碍插入到其他线程中。我想知道怎么做?

最佳答案

您询问的论文似乎是 "Respec: Efficient Online Multiprocessor Replay via Speculation and External Determinism" .论文提到:

We modified the Linux kernel to implement our techniques.

We therefore created a new Linux primitive, called a multithreaded fork, that creates a child process with the same number of threads as its parent.

所以当论文说的时候

Respec only checkpoints a thread when it is executing at a known safe point: kernel entry, kernel exit, or certain interruptible sleeps in the kernel that we have determined to be safe. The thread that initiates a multithreaded fork creates a barrier on which it waits until all other threads reach a safe point. Once all threads reach the barrier, the original thread creates the checkpoint, then lets the other threads continue execution.

我假设他们对 Linux 内核所做的修改是逻辑,即被记录的进程中的线程在到达这些“安全点”之一时将“进入”屏障(我也假设只有已经发布了一个“多线程分支”来创建屏障)。由于这是在内核中发生的,因此很容易实现一个屏障——实际上并没有任何动态发生。修改后的内核在这些战略安全点实现了屏障。

我还没有真正阅读这篇论文(只是略读了一些内容)。如果一个或多个线程正在执行不需要长时间进入内核的工作,我并不完全清楚会发生什么——系统似乎依赖于线程到达那些明确的安全点。所以线程不应该在 CPU 密集型循环中磨蹭太久(这对绝大多数程序来说可能不是问题):

Note that the actual execution time of an epoch may be longer than the epoch interval due to our barrier implementation; a checkpoint cannot be taken until all threads reach the barrier.

关于c++ - 在多线程程序中实现动态屏障的可能方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6902411/

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