void initialize_critical_section_and_spin_count(critical_section* section,
                                                unsigned spin)

This function initializes a critical section data structure (with spin count).


critical_section* section

A pointer to the critical section data structure to be initialized.

unsigned spin

The spin count for the critical section object.


On single processor systems, the spin count is set to zero then ignored. On multiprocessor systems, if the critical section is unavailable, the calling thread will spin the specified number of times prior to performing a wait operation on the semaphore associated with the critical section. If the critical section becomes free during the spin operation, the calling thread avoids the wait operation.

The threads of a process may use a critical section object for mutual exclusion synchronization.

The process is responsible for allocating the memory used by a critical section object, which it can do by declaring an object of the class critical_section. To initialize a critical section object prior to using it, one of the threads of the process must call this function or the function initialize_critical_section

Once a critical section object has been initialized, the threads of the process can pass a pointer to the object to the functions

This provides mutually exclusive access to a shared resource. For similar synchronization between the threads of different processes, a mutual exclusion semaphore may be used.

The object of the class critical_section may not be moved or copied. The process may not modify the object. Only the critical section functions may be used to manage critical section objects.

When memory is low, this function may raise the exception status::NoMemory.