Multi-thread applications commonly utilize condition variables for communication between threads. Condition variables allow threads to block and wait until a certain condition holds, and also enable threads to wake up their blocked peers notifying them about a change to the state of shared data. Quite often such notifications are delivered to all threads, while only a small number of specific threads is interested in it. This results in so-called futile wakeups, where threads receiving the notification wake up and resume their execution only to realize that the condition they are waiting for does not hold and they need to wait again. Those wakeups cause numerous context switches, increase lock contention and cache pressure, translating into lots of wasted computing cycles and energy. In this work, we propose to delegate conditions on which threads are waiting to the thread sending notifications. This enables the latter to evaluate the conditions and send the notification(s) only to the relevant thread(s), practically eliminating futile wakeups altogether. Our initial evaluation of this idea shows promising results, achieving 3-4x throughput improvement over legacy condition variables.
翻译:多线索应用程序通常使用条件变量进行线条之间的通信。 条件变量允许线条阻塞并等待特定条件的维持, 也允许线条唤醒被阻塞的同龄人, 通知共享数据状态的变化。 很多情况下, 这些通知被发送到所有线条上, 而只有一小部分特定的线条对此感兴趣。 这导致所谓的徒劳的唤醒, 接收通知的线条会醒来并恢复执行, 只意识到他们等待通知的条件无法维持, 需要再次等待。 这些觉醒会引发许多上下文开关, 增加锁定参数和缓存压力, 转化成大量浪费的计算周期和能量。 在这项工作中, 我们提议将线索等待发送通知的条件委托给所有线条。 这让后者能够评估条件, 并将通知发送到相关的线条上, 几乎完全消除徒劳的唤醒。 我们对这个想法的初步评估显示有希望的结果, 实现3-4x的负值改进了遗留条件变量。