Sign in Join
FPDoc Onlineexperiment

TCriticalSection class

In unit SyncObjs

Critical section.

Declaration

pascal
TCriticalSection = class(TSynchroObject)

Inheritance

  1. TCriticalSection
  2. TSynchroObject
  3. TObject

Descends from it: TLazMonitor

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.

See also

Methods

AcquirepublicEnter the critical section.
ReleasepublicLeave the critical section.
WaitForpublic
EnterpublicAlias for Acquire.
TryEnterpublicTry and obtain the critical section.
LeavepublicAlias for Release.
CreatepublicCreate a new critical section.
DestroypublicDestroy the criticalsection instance.

Inherited

From TObject (40)

AfterConstruction BeforeDestruction CheckDisposed ClassInfo ClassName ClassNameIs ClassParent ClassType CleanupInstance DefaultHandler DefaultHandlerStr Dispatch DispatchStr Disposed DisposeOf Equals FieldAddress Free FreeInstance GetDisposed GetHashCode GetInterface GetInterfaceByStr GetInterfaceEntry GetInterfaceEntryByStr GetInterfaceTable GetInterfaceWeak GetLastCastErrorInfo InheritsFrom InitInstance InstanceSize MethodAddress MethodName newinstance QualifiedClassName SafeCallException StringMessageTable SystemHasExtendedRTTI ToString UnitName

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.