diff --git a/Source/Test/Rewriting/Types/Threading/Monitor.cs b/Source/Test/Rewriting/Types/Threading/Monitor.cs
index bab1dd3bf..4d0a7563e 100644
--- a/Source/Test/Rewriting/Types/Threading/Monitor.cs
+++ b/Source/Test/Rewriting/Types/Threading/Monitor.cs
@@ -429,6 +429,13 @@ private SynchronizedBlock(CoyoteRuntime runtime, object syncObject)
this.DebugName = $"lock({this.ResourceId})";
}
+ ///
+ /// Called to clear out the cache of synchronized blocks in cases where an iteration
+ /// may have been aborted and the cache is no longer valid, and may even hold old
+ /// values that would otherwise not get cleaned up and could impact future iterations.
+ ///
+ internal static void ResetCache () => Cache.Clear();
+
///
/// Creates a new for synchronizing access
/// to the specified object and enters the lock.
diff --git a/Source/Test/SystematicTesting/TestingEngine.cs b/Source/Test/SystematicTesting/TestingEngine.cs
index c28441361..3cd574746 100644
--- a/Source/Test/SystematicTesting/TestingEngine.cs
+++ b/Source/Test/SystematicTesting/TestingEngine.cs
@@ -21,6 +21,8 @@
using Microsoft.Coyote.Telemetry;
using Microsoft.Coyote.Visualization;
+using SynchronizedBlock = Microsoft.Coyote.Rewriting.Types.Threading.Monitor.SynchronizedBlock;
+
namespace Microsoft.Coyote.SystematicTesting
{
///
@@ -201,6 +203,9 @@ private TestingEngine(Configuration configuration, TestMethodInfo testMethodInfo
// Create a client for gathering and sending optional telemetry data.
TelemetryClient = TelemetryClient.GetOrCreate(this.Configuration, this.LogWriter);
+
+ // Register to clean up the Monitor SynchronizedBlock cache.
+ this.RegisterEndIterationCallBack(_ => SynchronizedBlock.ResetCache());
}
///