need examples of a proper way to wait for a flag change in another thread without blocking the events?. In C++/windows.