Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da97502

Browse files
committed
Data synchronization for PyScopeTest.TestThread
1 parent 631bb43 commit da97502

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/embed_tests/TestPyScope.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,13 @@ public void TestThread()
337337
//add function to the scope
338338
//can be call many times, more efficient than ast
339339
ps.Exec(
340+
"import threading\n"+
341+
"lock = threading.Lock()\n"+
340342
"def update():\n" +
341-
" global res, th_cnt\n" +
342-
" res += bb + 1\n" +
343-
" th_cnt += 1\n"
343+
" global res, th_cnt\n" +
344+
" with lock:\n" +
345+
" res += bb + 1\n" +
346+
" th_cnt += 1\n"
344347
);
345348
}
346349
int th_cnt = 3;

0 commit comments

Comments
 (0)