Skip to content

Commit 8a59713

Browse files
committed
insert memory barriers to ensure main thread does not read stale values in TestThread
1 parent 7247da5 commit 8a59713

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/embed_tests/Modules.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ public void TestThread()
347347
{
348348
//ps.GetVariable<dynamic>("update")(); //call the scope function dynamicly
349349
_ps.update();
350+
Thread.MemoryBarrier();
350351
}
351352
});
352353
th.Start();
@@ -357,12 +358,14 @@ public void TestThread()
357358
{
358359
using (Py.GIL())
359360
{
361+
Thread.MemoryBarrier();
360362
cnt = ps.Get<int>("th_cnt");
361363
}
362364
Thread.Yield();
363365
}
364366
using (Py.GIL())
365367
{
368+
Thread.MemoryBarrier();
366369
var result = ps.Get<int>("res");
367370
Assert.AreEqual(101 * th_cnt, result);
368371
}

0 commit comments

Comments
 (0)