Critical section class for Windows and UNIX platforms. More...
#include <mi32/critsec.h>
Classes | |
| class | LOCK |
| Control entering an instance of a CRITICALSECTION upon initialization and released when out of scope. More... | |
Public Member Functions | |
| CRITICALSECTION (unsigned long SpinCount=0) | |
| ~CRITICALSECTION () | |
| unsigned long | SetSpinCount (unsigned long SpinCount) |
Critical section class for Windows and UNIX platforms.
| MITHREAD::CRITICALSECTION::CRITICALSECTION | ( | unsigned long | SpinCount = 0 |
) |
Default constructor.
A "critical section" is a fancy name for an in-process only mutex. Given that, the "SpinCount" is used to delay the acquisition of that system mutex and the expensive transfer into and out of kernel mode. The use of the "SpinCount" is to determine how many times, in a loop, that a check is done to see if the lock is granted. The downside to this is that the spinning takes up CPU time in the loop doing the checks. Therefore using the "SpinCount" is a gamble to see if the loop method will take less time than the kernel transitions for the mutex object. Rule of thumb: do not use the "SpinCount" to protect code that itself makes a kernel transition (I/O calls) or is a time consuming operation. From MSDN Docs: You can improve performance significantly by choosing a small spin count for a critical section of short duration. The heap manager uses a spin count of roughly 4000 for its per-heap critical sections. This gives great performance and scalability in almost all worst-case scenarios.
| SpinCount | How many times to check and yield before allocating a system resource |
| MITHREAD::CRITICALSECTION::~CRITICALSECTION | ( | ) |
Destructor.
| unsigned long MITHREAD::CRITICALSECTION::SetSpinCount | ( | unsigned long | SpinCount | ) |
Set spin count for the critical section See the constructor for the documentation on how to use the "SpinCount".
| SpinCount | How many times to check and yield before allocating a system resource |
1.6.1