Multi-Core and Hyper-Threading Technology
7
7-27
If an application thread must remain idle for a long time, the application
should use a thread blocking API or other method to release the idle
processor. The techniques discussed here apply to traditional MP
system, but they have an even higher impact on IA-32 processors that
support Hyper-Threading Technology.
Typically, an operating system provides timing services, for example
Sleep(
dwMilliseconds
)
6
; such variables can be used to prevent frequent
checking of a synchronization variable.
Another technique to synchronize between worker threads and a control
loop is to use a thread-blocking API provided by the OS. Using a
thread-blocking API allows the control thread to use less processor
cycles for spinning and waiting. This gives the OS more time quanta to
schedule the worker threads on available processors. Furthermore, using
a thread-blocking API also benefits from the system idle loop
optimization that OS implements using the HLT instruction.
User/Source Coding Rule 23. (H impact, M generality) Use a
thread-blocking API in a long idle loop to free up the processor.
Using a spin-wait loop in a traditional MP system may be less of an
issue when the number of runnable threads is less than the number of
processors in the system. If the number of threads in an application is
expected to be greater than the number of processors (either one
processor or multiple processors), use a thread-blocking API to free up
processor resources. A multithreaded application adopting one control
thread to synchronize multiple worker threads may consider limiting
worker threads to the number of processors in a system and use
thread-blocking APIs in the control thread.
6.
The Sleep() API is not thread-blocking, because it does not guarantee the processor will be
released.
Example 7-5
(a)
shows an example of using Sleep(0), which does not always realize the
processor to another thread.
Summary of Contents for ARCHITECTURE IA-32
Page 1: ...IA 32 Intel Architecture Optimization Reference Manual Order Number 248966 013US April 2006...
Page 220: ...IA 32 Intel Architecture Optimization 3 40...
Page 434: ...IA 32 Intel Architecture Optimization 9 20...
Page 514: ...IA 32 Intel Architecture Optimization B 60...
Page 536: ...IA 32 Intel Architecture Optimization C 22...