#6 (Supposedly) better thread contention performance


I suggest to insert an assembly instruction "PAUSE" in the busy waiting loop of FastMM, if "NeverSleepOnThreadContention" is defined.

As I read from Intel's Developer's Manual, the instruction "PAUSE" is recommended to be put inside a loop if very high frequency "spinning" (busy waiting loop) is expected. It provides the processor a "hint" so that it would slow the spinning down a bit, lowering the power consumption, and may even improve the overall performance.

I have tested and confirmed this behavior in a lockfree message queue I wrote: On a 2-way Xeon (with HyperThreading) system, with 4 producer threads and 4 consumer threads exchanging 4 million messages on the same queue, the overall performance is 3~8% higher if I put "PAUSE" instruction in my busy waiting loop. (I suspect the speed up is becuase of the HT - if one thread PAUSES in the busy waiting loop, another thread, which is not logically stuck, on the same physical processor may actually get more share of cycles!)

In addition, PAUSE does not harm multithreading performance on single CPU system, becuase it does not change the time slice allotted to the spinning thread.

email: kamiochisuna {_at_} hotmail (_d0t_} com


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks