Skip to content

Commit 925c166

Browse files
authored
Fix synchronization in PyScopeTest.TestThread as suggested in da97502 (#1070)
Fixes #1067.
1 parent 653a932 commit 925c166

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/embed_tests/TestPyScope.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,16 @@ public void TestThread()
338338
//add function to the scope
339339
//can be call many times, more efficient than ast
340340
ps.Exec(
341-
"import clr\n" +
342-
"from System.Threading import Thread\n" +
341+
"import threading\n" +
342+
"lock = threading.Lock()\n" +
343343
"def update():\n" +
344-
" global res, th_cnt\n" +
344+
" global res, th_cnt\n" +
345+
" with lock:\n" +
345346
" res += bb + 1\n" +
346-
" Thread.MemoryBarrier()\n" +
347347
" th_cnt += 1\n"
348348
);
349349
}
350-
int th_cnt = 3;
350+
int th_cnt = 100;
351351
for (int i = 0; i < th_cnt; i++)
352352
{
353353
System.Threading.Thread th = new System.Threading.Thread(() =>
@@ -368,9 +368,8 @@ public void TestThread()
368368
{
369369
cnt = ps.Get<int>("th_cnt");
370370
}
371-
Thread.Sleep(10);
371+
Thread.Yield();
372372
}
373-
Thread.MemoryBarrier();
374373
using (Py.GIL())
375374
{
376375
var result = ps.Get<int>("res");

0 commit comments

Comments
 (0)