[Overview][Constants][Types][Classes] | Reference for unit 'syncobjs' (#fcl) |
[Properties (by Name)] [Methods (by Name)] [Events (by Name)]
Critical section
Source position: syncobjs.pp line 38
type TCriticalSection = class(TSynchroObject) |
||
public |
||
procedure Acquire; override; |
|
Enter the critical section |
procedure Release; override; |
|
Leave the critical section |
procedure Enter; |
|
Alias for Acquire |
procedure Leave; |
|
Alias for Release |
constructor Create; |
|
Create a new critical section. |
destructor Destroy; override; |
|
Destroy the criticalsection instance |
end; |
|
Critical section |
|
| | ||
|
Abstract synchronization object |
|
| | ||
TObject |
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.
|
Enter the critical section |
|
|
Leave the critical section |
No notes exist for this page yet.