Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
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
41 changes: 28 additions & 13 deletions 41 src/embed_tests/Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void TestEval()
ps.Set("a", 1);
var result = ps.Eval<int>("a + 2");
Assert.AreEqual(3, result);
}
}
}

/// <summary>
Expand Down Expand Up @@ -286,7 +286,7 @@ public void TestImportScopeFunction()
public void TestVariables()
{
using (Py.GIL())
{
{
(ps.Variables() as dynamic)["ee"] = new PyInt(200);
var a0 = ps.Get<int>("ee");
Assert.AreEqual(200, a0);
Expand Down Expand Up @@ -338,34 +338,49 @@ public void TestThread()
" th_cnt += 1\n"
);
}
int th_cnt = 100;
const int th_cnt = 100;
int locked = 0, unlocked = 0, started = 0;
for (int i = 0; i < th_cnt; i++)
{
System.Threading.Thread th = new System.Threading.Thread(() =>
ThreadPool.QueueUserWorkItem(_ =>
// var th = new System.Threading.Thread(() =>
{
Interlocked.Increment(ref started);
using (Py.GIL())
{
Interlocked.Increment(ref locked);
//ps.GetVariable<dynamic>("update")(); //call the scope function dynamicly
_ps.update();
}
Interlocked.Increment(ref unlocked);
});
th.Start();
// th.Start();
}
//equivalent to Thread.Join, make the main thread join the GIL competition
int cnt = 0;
while (cnt != th_cnt)
int result = 0;
var wait = new Thread(() =>
{
int cnt = 0;
while (cnt != th_cnt)
{
using (Py.GIL())
{
cnt = ps.Get<int>("th_cnt");
}
Thread.Yield();
}

using (Py.GIL())
{
cnt = ps.Get<int>("th_cnt");
result = ps.Get<int>("res");
}
Thread.Yield();
}
using (Py.GIL())
});
wait.Start();
if (!wait.Join(timeout: TimeSpan.FromSeconds(30)))
{
var result = ps.Get<int>("res");
Assert.AreEqual(101 * th_cnt, result);
Assert.Fail($"started: {started} locked: {locked} unlocked: {unlocked}");
}
Assert.AreEqual(101 * th_cnt, result);
}
finally
{
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.