help files
Z505 | PasWiki | FUQ | Search | Main Docs | API Guide



[Overview][Constants][Types][Classes][Procedures and functions][Variables] Reference for unit 'System' (#rtl)

EnterCriticalsection

Enter a critical section

Declaration

Source position: threadh.inc line 146

procedure EnterCriticalsection(

  var cs: TRTLCriticalSection

);

Description

EnterCriticalSection will suspend the current thread if another thread has currently entered the critical section. When the other thread has left the critical section (through LeaveCriticalSection), the current thread resumes execution. The result is that only 1 thread is executing code which is protected by a EnterCriticalsection and LeaveCriticalSection pair.

The critical section must have been initialized with InitCriticalSection prior to a call to EnterCriticalsection.

A call to EnterCriticalsection must always be matched by a call to LeaveCriticalSection. To avoid problems, it is best to include the code to be execute in a try...finally block, as follows:

EnterCriticalSection(Section);
  Try 
    // Code to be protected goes here.
  Finally
    LeaveCriticalSection(Section);
  end;

For performance reasons it is best to limit the code between the entering and leaving of a critical section as short as possible.

See also

InitCriticalsection

  

Initialize a critical section

DoneCriticalsection

  

Clean up a critical section.

LeaveCriticalsection

  

Leave a critical section

Notes

 No notes exist for this page yet. 





lufdoc, Powtils, fpc, freepascal, delphi, kylix, c/c++, mysql, cgi web framework docs, Z505