Adding State to the Update Notification Pattern, Part 3 -- Raymond Chen
Adding State to the Update Notification Pattern, Part 3
by Raymond Chen
From the article:
Last time, we developed a stateful but coalescing update notification, and we noted that the code does a lot of unnecessary work because the worker thread calculates all the matches, even if the work has been superseded by another request.
We can add an optimization to abandon the background work if it notices that its efforts are going to waste: Periodically check whether there is any pending text. This will cost us a mutex, however, to protect access to
m_pendingText
from multiple threads.