To use a critical section

  1. Create a global instance of TCriticalSection.
  2. Call the Acquire method to lock out other threads while accessing global memory.
  3. Call the Release method so other threads can access the memory by calling Acquire.

The following code has a global critical section variable LockXY that blocks access to the global variables X and Y. To use X or Y, a thread must surround that use with calls to the critical section such as shown here:

LockXY.Acquire; try

LockXY.Release end;

Warning: Critical sections only work if every thread uses them to access global memory. Otherwise, problems of simultaneous access can occur.

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment