critical_section Class
A non-reentrant mutex which is explicitly aware of the Concurrency Runtime.
class critical_section;
Name | Description |
---|---|
native_handle_type |
A reference to a critical_section object. |
Name | Description |
---|---|
critical_section::scoped_lock Class | An exception safe RAII wrapper for a critical_section object. |
Name | Description |
---|---|
critical_section | Constructs a new critical section. |
~critical_section Destructor | Destroys a critical section. |
Name | Description |
---|---|
lock | Acquires this critical section. |
native_handle | Returns a platform specific native handle, if one exists. |
try_lock | Tries to acquire the lock without blocking. |
try_lock_for | Tries to acquire the lock without blocking for a specific number of milliseconds. |
unlock | Unlocks the critical section. |
For more information, see Synchronization Data Structures.
critical_section
Header: concrt.h
Namespace: concurrency
Constructs a new critical section.
critical_section();
Destroys a critical section.
~critical_section();
It is expected that the lock is no longer held when the destructor runs. Allowing the critical section to destruct with the lock still held results in undefined behavior.
Acquires this critical section.
void lock();
It is often safer to utilize the scoped_lock construct to acquire and release a critical_section
object in an exception safe way.
If the lock is already held by the calling context, an improper_lock exception will be thrown.
Returns a platform specific native handle, if one exists.
native_handle_type native_handle();
A reference to the critical section.
A critical_section
object is not associated with a platform specific native handle for the Windows operating system. The method simply returns a reference to the object itself.
An exception safe RAII wrapper for a critical_section
object.
class scoped_lock;
Constructs a scoped_lock
object and acquires the critical_section
object passed in the _Critical_section
parameter. If the critical section is held by another thread, this call will block.
explicit _CRTIMP scoped_lock(critical_section& _Critical_section);
_Critical_section
The critical section to lock.
Destroys a scoped_lock
object and releases the critical section supplied in its constructor.
~scoped_lock();
Tries to acquire the lock without blocking.
bool try_lock();
If the lock was acquired, the value true
; otherwise, the value false
.
Tries to acquire the lock without blocking for a specific number of milliseconds.
bool try_lock_for(unsigned int _Timeout);
_Timeout
The number of milliseconds to wait before timing out.
If the lock was acquired, the value true
; otherwise, the value false
.
Unlocks the critical section.
void unlock();