什么先运行:分区器或组合器?(What runs first: the partitioner or the combiner?)
我想知道分区器和组合器,哪个先运行?
我认为它是第一个partitiner,然后组合器,然后键被重定向到不同的减速器,看起来像分区器,所以我很困惑。 请帮助我理解。
I was wondering between partitioner and combiner, which runs first?
I was of the opinion it is the partitiner first and then combiner and then the keys are redirected to different reducers, which appears like the partitioner, and so I'm confused. Please help me understand.
原文:https://stackoverflow.com/questions/22061210
最满意答案
std::condition_variable
不指定在调用notify_one
时哪个等待线程被唤醒。 因此,您应该编写不关心哪个线程被唤醒的代码。 标准模式是无论哪个线程被唤醒,该线程都应该完成需要完成的工作。如果您要求线程按特定顺序唤醒,请使用其他机制。 例如,您可以为每个线程分别设置
std::condition_variable
,然后在需要工具时将线程放入队列中。 当一个线程递交工具时,它可以发信号通知与队列前面的线程相对应的条件变量。 那个线程会被唤醒,其他线程将保持睡眠状态(模仿虚假唤醒)。
std::condition_variable
does not specify which waiting thread is woken when you callnotify_one
. You should therefore write code that doesn't care which thread is woken. The standard pattern is that whichever thread is woken, that thread should do the work that needs to be done.If you require that the threads are woken in a specific order, then use a different mechanism. You could, for example, have a separate
std::condition_variable
for each thread, and then put the threads in a queue when they need tools. As a thread hands in the tools, it could then signal the condition variable corresponding to the thread at the front of the queue. That thread will then be woken, and the others will remain sleeping (modulo spurious wake-ups).
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
std::condition_variable不指定在调用notify_one时哪个等待线程被唤醒。 因此,您应该编写不关心哪个线程被唤醒的代码。 标准模式是无论哪个线程被唤醒,该线程都应该完成需要完成的工作。 如果您要求线程按特定顺序唤醒,请使用其他机制。 例如,您可以为每个线程分别设置std::condition_variable ,然后在需要工具时将线程放入队列中。 当一个线程递交工具时,它可以发信号通知与队列前面的线程相对应的条件变量。 那个线程会被唤醒,其他线程将保持睡眠状态(模仿虚假唤醒)。 s ...
-
如何等待多个线程完成(使用C ++ 11线程)?(How to wait for multiple threads to finish (with c++11 threads)?)[2024-03-25]
这里有一个快速收集的问题一目了然。 wait()是递归的,没有解锁其唯一锁(根据来自Detonar的评论) while (!m_ready) {}不在内存中(尝试编译一些优化,看看会发生什么!) 如果工作线程在wait()被调用之前完成, 在等待条件变量之前没有执行检查。 由于工作线程已完成, 它永远不会醒来。 显然你必须检查线程是否可以在等待条件变量之前在互斥体中被唤醒。 Here's a quick collection of issues from a glance. wait() is recurs ... -
裸条件变量和互斥量是不够的:条件变量需要与某个共享状态(因此名称)上的条件配对。 一个简单的例子是用一个标志变量来扩充你的condition结构: struct condition { pthread_cond_t cond_var; pthread_mutex_t lock; int flag; }; 其中flag变量受lock互斥锁保护。 然后,工作线程可以使用条件变量来等待设置flag : void *Woker() { condition new_obj; ...
-
标准没有给出这样的保证, notify_one可以唤醒当前正在等待的任何线程(§30.5.1): void notify_one() noexcept; 效果:如果有任何线程被阻塞等待*this ,则取消阻止其中一个theads。 确保特定线程对事件做出反应的唯一方法是唤醒所有线程,然后使用一些额外的同步机制将除了正确的线程之外的所有线程发送回休眠状态。 由于平台必须满足的要求,这是一个基本限制:通常条件变量以等待线程进入挂起状态的方式实现,并且在发生通知之前不会再次由系统调度。 不需要调度程序实现来提供用 ...
-
这看起来不像condition_variable代码。 它看起来像是condition_variable_any代码。 后者具有模板等待功能。 前者不。 N2406可能会说明你所看到的内容。 在N2406中, condition_variable_any改为gen_cond_var ,否则,类型相同。 本文描述了一种死锁情况,在这种情况下,除非要非常小心地确保_M_mutex和__lock以非常特定的顺序锁定和解锁, __lock会导致_M_mutex 。 尽管您展示的代码和N2406中的代码并不相同,但我 ...
-
您违反了标准呼叫wait的要求: void wait(unique_lock&lock); 要求:lock.owns_lock()为true且lock.mutex()被调用线程锁定,并且: - 没有其他线程在等于这个condition_variable对象或 - lock.mutex()为所有并发等待(通过wait或timed_wait)线程提供的每个锁参数返回相同的值。 您可以同时等待其lock引用不同mutex 。 所以你不满足在condition_variable上调用wait的先决condition ...
-
我有以下想法:保持线程的计数器等待B的“好”值,其中第一个被唤醒将缓存那个好的价值并让其他读者到那个时刻阅读它。 我们让新读者远离等待循环,直到所有前一轮完成。 这是代码大纲: final AtomicInteger A = new AtomicInteger(-1), B = new AtomicInteger(-1); int cachedB = -1; int readersCount; int waitForB() throws InterruptedException { // Can be ...
-
如何确保所有从属线程都等待条件变量?(How to make sure all slave threads are waited for conditional variable?)[2021-11-21]
你有竞争条件 - 设置标志和通知从属线程不是原子的。 因此,您必须在修改主线程中的data_ready标志之前锁定data_ready_mutex 。 这将消除竞争条件,从属线程将看到data_ready false并转到等待条件变量并将被通知,或者它将仅在data_ready设置为true之后获取互斥锁,因此它将不会等待。 You have race condition - setting flag and notifying slave threads is not atomic. So you jus ...