"are delphi simple types thread safe?" Code Answer


you are probably saying about atomic variables. integer and boolean variables are atomic. booleans (bytes) are always atomic, integers (32-bits) are atomic because the compiler properly aligns them.

atomicity means that any read or write operation is executed as a whole. if a thread a executes atomic write and a thread b atomic read of the same data at the same time, the data read by thread b is always consistent - it is impossible that some bits read by thread b are obtained from the current write operation and some bits from the previous write (by thread a)

but atomicity does not mean thread safety - you can easily write unsafe code with atomic variables. a variable itself cannot be threadsafe - only a code as a whole can be (or not) threadsafe.

By RudiBoy on March 13 2022

Answers related to “are delphi simple types thread safe?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.