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

Skip to content

Add Lock synchronization to PyScopeTest.TestThread #1070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/embed_tests/TestPyScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,16 @@ public void TestThread()
//add function to the scope
//can be call many times, more efficient than ast
ps.Exec(
"import clr\n" +
"from System.Threading import Thread\n" +
"import threading\n" +
"lock = threading.Lock()\n" +
"def update():\n" +
" global res, th_cnt\n" +
" global res, th_cnt\n" +
" with lock:\n" +
" res += bb + 1\n" +
" Thread.MemoryBarrier()\n" +
" th_cnt += 1\n"
);
}
int th_cnt = 3;
int th_cnt = 100;
for (int i = 0; i < th_cnt; i++)
{
System.Threading.Thread th = new System.Threading.Thread(() =>
Expand All @@ -368,9 +368,8 @@ public void TestThread()
{
cnt = ps.Get<int>("th_cnt");
}
Thread.Sleep(10);
Thread.Yield();
}
Thread.MemoryBarrier();
using (Py.GIL())
{
var result = ps.Get<int>("res");
Expand Down