In Chromium, the UI thread's message pump processes work in a round-robin fashion from two primary sources: the Chrome Task Queue and the native OS Message Queue (e.g., the Windows Message Queue). Bugs may occur when the thread blocks and spins a nested message loop, causing re-entrancy into UI code that destroys objects currently in use by the blocked outer stack frames.
When writing UI code, be aware of the following mechanisms that introduce implicit nested message loops:
SendMessage (Windows): If a SendMessage call crosses thread boundaries, the sending thread blocks until the target thread responds. While blocked, the OS will automatically dispatch incoming non-queued messages to the waiting thread.SendMessage call to the HWND during a cross-thread call. When citing a direct SendMessage call as a risk, a clear code reference must be provided. SendMessage calls do not suddenly appear without a caller. In addition, Chrome cannot mitigate SendMessage calls from third-parties. These external callers are already running code inside the environment and can perform more damaging actions.