background: synchronization of an emulated microcontroller (Motorola MC68331) at 20 Mhz, running in thread A, to an emulated DSP (Motorola 56300) at 120 MHz, running in thread B.
I need synchronization at audio rate, which results in synchronization 44100 times per second.
The current approach is to use a std::condition_variable, but the overhead of wait() is too high. At the moment I'm profiling on a Windows system, however, this has to work on Win, Mac and possibly Linux/Android, too.
In particular, the issue is a jmp instruction inside of SleepConditionvariableSRW, which is very costly:
I already tried some other options. Various variants of sleep are too imprecise and usually take way too long, the best one can get out of Windows is roughly one millisecond, however, the maximum sleep time should not be more than 1/44100 seconds => about 22us:
The closest one can get on Windows is to use CreateWaitableTimerEx with the high precision flag, but even in that case, the overhead of these functions is even higher than the std::condition_variable.
What I also tried: a spinloop with std::this_thread::yield, which results in more CPU usage in general.
Is there anything I am missing / could try? More than 50% of CPU time is wasted in the wait code, which I'd like to eliminate.
Thanks in advance!

