Author Topic: Record Locking  (Read 3716 times)

Andy Anderson

  • Newbie
  • Posts: 6
Record Locking
« on: August 10, 2014, 11:29:20 pm »

I've read all the references I
could find but couldn't find an
example to put it all together.

Can someone supply a link to an
example of non OOP record/region

Thanks in advance.

Andy Anderson

  • Newbie
  • Posts: 6
Re: Record Locking
« Reply #1 on: August 13, 2014, 07:02:45 pm »
Well, I guess there is no way in Free Pascal
to lock/unlock records/regions for Windows

My workaround will be to use the LOCKFILEEX/UNLOCKFILEEX API's.


  • Hero Member
  • *****
  • Posts: 758
    • J-Software
Re: Record Locking
« Reply #2 on: August 13, 2014, 07:28:16 pm »
It depends on what you need.

If you need to lock a shared variable you can use critical sections, mutexes, semaphores, or events.

Critical sections are probably by far the simplest to understand. You can take a look at the syncobjs unit to see some easy to use object oriented classes for this.

Edit: Ah, if you need non-OOP code you can also take a look at that unit. It uses the standard platform independent interface in the RTL to do the different things.

For example, a critical section:

Code: [Select]
var cs: TRTLCriticalSection;

   // Call this to initialize

   // And this when you are done with it

   // And to lock some resource
   ... do stuff with whatever needs locking

The CS variable would be a single lock that only prevents others from entering the same. So you will want one for each thing that you are locking.
« Last Edit: August 13, 2014, 07:33:27 pm by Laksen »

Andy Anderson

  • Newbie
  • Posts: 6
Re: Record Locking
« Reply #3 on: August 15, 2014, 09:07:03 pm »
Thanks, Laksen. I'll take a look at the critical sections material. Curiously, the Windows API's I mentioned require a type specification almost identical to the Unix based FLock type for the FpFcntl call.


TinyPortal © 2005-2018