Skip to Main Content
Mastering Delphi Programming: A Complete Reference Guide
book

Mastering Delphi Programming: A Complete Reference Guide

by Primož Gabrijelčič
November 2019
Beginner to intermediate content levelBeginner to intermediate
674 pages
15h
English
Packt Publishing
Content preview from Mastering Delphi Programming: A Complete Reference Guide

Critical sections

The easiest way to explain the use of critical sections is with an example. As the ReadWrite example is still fresh in your mind, I'll return to it. This program implements—in addition to the unsafe reading/writing approach—a code that reads and writes data with additional protection from a critical section lock.

This critical section is created when a form is created, and destroyed when the form is destroyed. There is only one critical section object shared by both threads:

procedure TfrmReadWrite.FormCreate(Sender: TObject);begin  FLock := TCriticalSection.Create;end;procedure TfrmReadWrite.FormDestroy(Sender: TObject);begin  FreeAndNil(FLock);end;

When a reader wants to read from FPValue^, it will firstly acquire the critical ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Delphi GUI Programming with FireMonkey

Delphi GUI Programming with FireMonkey

Andrea Magni
Delphi Cookbook - Third Edition

Delphi Cookbook - Third Edition

Daniele Spinetti, Daniele Teti

Publisher Resources

ISBN: 9781838989118Other