If multiple threads are executing class procedure TDjelatBL.Test
, is there going to be an exception due to accessing variable iPublic
?
The point of my question is if accessing same variable/object/constant from two or more threads simultaneously will raise an exception. I assume that nature of change of variable/object does not change memory allocation like changing size of an array.
Closest question (comparing to this one) I have found is Is a Delphi global procedure threadsafe and Are Delphi simple types thread safe? but raising of an exception is never mentioned.
unit MTTest;
interface
uses
System.SysUtils, System.Classes;
type
TDjelatBL = class
public
class procedure Test;
end;
var
iPublic: Integer;
StringList: TStringList;
implementation
class procedure TDjelatBL.Test;
var
i: Integer;
begin
StringList.Add('x');
for i := 1 to 1000000000 do
begin
iPublic := iPublic + StringList.Count;
end;
end;
initialization
StringList := TStringList.Create;
finalization
StringList.Free;
StringList.free
, but more likely onStringList.Count
, and possibly onStringList.Add
as well. – Ken Bourassa