Declaration¶
Source position: syncobjs.pp line 115
Inheritance¶
Description¶
TCriticalSection is a class wrapper around the low-level TRTLCriticalSection routines. It simply calls the RTL routines in the system unit for critical section support.
A critical section is a resource which can be owned by only 1 caller: it can be used to make sure that in a multithreaded application only 1 thread enters pieces of code protected by the critical section.
Typical usage is to protect a piece of code with the following code (MySection is a TCriticalSection instance):
// Previous code
MySection.Acquire;
Try
// Protected code
Finally
MySection.Release;
end;
// Other code.
The protected code can be executed by only 1 thread at a time. This is useful for instance for list operations in multithreaded environments.
Methods¶
| Member | Visibility | Description |
|---|---|---|
| Acquire | public | Enter the critical section. |
| Create | public | Create a new critical section. |
| Destroy | public | Destroy the criticalsection instance. |
| Enter | public | Alias for Acquire. |
| Leave | public | Alias for Release. |
| Release | public | Leave the critical section. |
| TryEnter | public | Try and obtain the critical section. |
| WaitFor | public |