8000 attempt to fix PyScopeTest.TestThread() reading stale value from res … · pythonnet/pythonnet@4b94a46 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 4b94a46

Browse files
committed
attempt to fix PyScopeTest.TestThread() reading stale value from res in Python 2.7 x64
1 parent 39b2347 commit 4b94a46

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/embed_tests/TestPyScope.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading;
23
using NUnit.Framework;
34
using Python.Runtime;
45

@@ -337,9 +338,12 @@ public void TestThread()
337338
//add function to the scope
338339
//can be call many times, more efficient than ast
339340
ps.Exec(
341+
"import clr\n" +
342+
"from System.Threading import Thread\n" +
340343
"def update():\n" +
341344
" global res, th_cnt\n" +
342345
" res += bb + 1\n" +
346+
" Thread.MemoryBarrier()\n" +
343347
" th_cnt += 1\n"
344348
);
345349
}
@@ -364,8 +368,9 @@ public void TestThread()
364368
{
365369
cnt = ps.Get<int>("th_cnt");
366370
}
367-
System.Threading.Thread.Sleep(10);
371+
Thread.Sleep(10);
368372
}
373+
Thread.MemoryBarrier();
369374
using (Py.GIL())
370375
{
371376
var result = ps.Get<int>("res");

0 commit comments

Comments
 (0)
0