This commit is contained in:
Michael Schimmel
2025-07-14 16:44:29 +02:00
parent d0ad547aa3
commit 6f0b927a05
7 changed files with 177 additions and 169 deletions
+21 -36
View File
@@ -34,9 +34,6 @@ type
[TestCase('Writeable', '10,20')]
procedure TestWriteableMutable(InitialValue, NewValue: Integer);
[Test]
procedure TestWriteableMutable_SignalOnSameValue;
[Test]
[TestCase('Protected', '100,200')]
procedure TestProtectedMutable_Delegation(InitialValue, NewValue: Integer);
@@ -106,7 +103,8 @@ var
func: TFunc<Integer>;
begin
callCount := 0;
func := function: Integer
func :=
function: Integer
begin
Inc(callCount);
Result := 42;
@@ -125,10 +123,7 @@ var
func: TFunc<Integer>;
begin
source := TEvent.CreateEvent;
func := function: Integer
begin
Result := 123;
end;
func := function: Integer begin Result := 123; end;
mutable := TMutable<Integer>.Construct(source.Signal, func);
lazy := TLazy<Integer>.Create(mutable);
@@ -156,19 +151,6 @@ begin
subscription.Unsubscribe;
end;
procedure TTestCoreMutable.TestWriteableMutable_SignalOnSameValue;
var
writeable: TWriteable<Integer>;
subscriber: TSignal.ISubscriber;
subscription: TSignal.TSubscription;
begin
writeable := TWriteable<Integer>.CreateWriteable(100);
subscriber := TTestSubscriber.Create(SubscriberCallback);
subscription := writeable.Changed.Subscribe(subscriber);
subscription.Unsubscribe;
end;
procedure TTestCoreMutable.TestProtectedMutable_Delegation(InitialValue, NewValue: Integer);
var
writeable: TWriteable<Integer>;
@@ -203,21 +185,24 @@ begin
for i := 0 to ThreadCount - 1 do
begin
threads := threads + [TThread.CreateAnonymousThread(
procedure
var
j: Integer;
begin
for j := 1 to Iterations do
begin
// This is an intentional race condition to test lock stability.
// The lock protects the GetValue calls individually,
// preventing memory corruption during concurrent access.
var curr := writeable.Value;
writeable.Value := curr + 1;
end;
end
)];
threads :=
threads
+ [
TThread.CreateAnonymousThread(
procedure
var
j: Integer;
begin
for j := 1 to Iterations do
begin
// This is an intentional race condition to test lock stability.
// The lock protects the GetValue calls individually,
// preventing memory corruption during concurrent access.
var curr := writeable.Value;
writeable.Value := curr + 1;
end;
end
)];
end;
for var thread in threads do