首页 \ 问答 \ 什么先运行:分区器或组合器?(What runs first: the partitioner or the combiner?)

什么先运行:分区器或组合器?(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
更新时间:2022-02-14 09:02

最满意答案

std::condition_variable不指定在调用notify_one时哪个等待线程被唤醒。 因此,您应该编写不关心哪个线程被唤醒的代码。 标准模式是无论哪个线程被唤醒,该线程都应该完成需要完成的工作。

如果您要求线程按特定顺序唤醒,请使用其他机制。 例如,您可以为每个线程分别设置std::condition_variable ,然后在需要工具时将线程放入队列中。 当一个线程递交工具时,它可以发信号通知与队列前面的线程相对应的条件变量。 那个线程会被唤醒,其他线程将保持睡眠状态(模仿虚假唤醒)。


std::condition_variable does not specify which waiting thread is woken when you call notify_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).

相关问答

更多
  • std::condition_variable不指定在调用notify_one时哪个等待线程被唤醒。 因此,您应该编写不关心哪个线程被唤醒的代码。 标准模式是无论哪个线程被唤醒,该线程都应该完成需要完成的工作。 如果您要求线程按特定顺序唤醒,请使用其他机制。 例如,您可以为每个线程分别设置std::condition_variable ,然后在需要工具时将线程放入队列中。 当一个线程递交工具时,它可以发信号通知与队列前面的线程相对应的条件变量。 那个线程会被唤醒,其他线程将保持睡眠状态(模仿虚假唤醒)。 s ...
  • 这里有一个快速收集的问题一目了然。 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 ...
  • 你有竞争条件 - 设置标志和通知从属线程不是原子的。 因此,您必须在修改主线程中的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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)