![Intel ARCHITECTURE IA-32 Reference Manual Download Page 375](http://html1.mh-extra.com/html/intel/architecture-ia-32/architecture-ia-32_reference-manual_2073155375.webp)
Multi-Core and Hyper-Threading Technology
7
7-29
In general, OS function calls should be used with care when
synchronizing threads. When using OS-supported thread
synchronization objects (critical section, mutex, or semaphore),
preference should be given to the OS service that has the least
synchronization overhead, such as a critical section.
Example 7-5
Coding Pitfall using Spin Wait Loop
(a) A spin-wait loop attempts to release the processor incorrectly. It experiences a performance
penalty if the only worker thread and the control thread runs on the same physical processor
package.
// Only one worker thread is running,
// the control loop waits for the worker thread to complete.
ResumeWorkThread(thread_handle);
While (!task_not_done ) {
Sleep(0) // Returns immediately back to spin loop.
…
}
(b) A polling loop frees up the processor correctly.
// Let a worker thread run and wait for completion.
ResumeWorkThread(thread_handle);
While (!task_not_done ) {
Sleep(FIVE_MILISEC)
// This processor is released for some duration, the processor
// can be used by other threads.
…
}
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...