November 2019
Beginner to intermediate
674 pages
15h
English
In all the examples so far, I used a simple coding style:
// acquire access// work with shared resource// release access
For example, the IncDec demo from this chapter contains the following code:
FSpinlock.Enter;value := FValue;FValue := value - 1;FSpinlock.Exit;
In reality, I don't code resource locking in that way. I'm a strong proponent of the thought that all resource management pairs, such as create/destroy, acquire/release, beginupdate/endupdate, and so on should, if at all possible, be written in a try..finally block. I would therefore write the previous example as follows:
FSpinlock.Enter;try value := FValue; FValue := value - 1;finally FSpinlock.Exit;end;
This approach has two big advantages. One is ...
Read now
Unlock full access