
On 7 Sep 2013 at 10:59, Marcello Pietrobon wrote:
The latest version, by Ion, using his spin_wait class solves completely the problem, at least in the cases I could test.
An interesting note: Microsoft has introduced a function that completely solves the sleep(1) problem: http://msdn.microsoft.com/en-us/library/system.threading.thread.spinwait.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1
No comments on their decision to provide it only for their .net library and not for C++ as it seems to be.
It's very, very easy to roll your own in C++. Simply loop the PAUSE x86 instruction (PAUSE = REP NOP, i.e. loop no-op). Hyperthreading CPUs understand this means to go execute the other Hyperthread instead. Niall -- Currently unemployed and looking for work. Work Portfolio: http://careers.stackoverflow.com/nialldouglas/