Skip to content
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

[wasm][mt] Guard more places for blocking wait on JS interop threads #98508

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ private void DisposeCore()

private void AcquireCore()
{
#if FEATURE_WASM_MANAGED_THREADS
Thread.AssureBlockingPossible();
#endif
Interop.Sys.LowLevelMonitor_Acquire(_nativeMonitor);
}

Expand All @@ -41,6 +44,9 @@ private void ReleaseCore()

private void WaitCore()
{
#if FEATURE_WASM_MANAGED_THREADS
Thread.AssureBlockingPossible();
#endif
Interop.Sys.LowLevelMonitor_Wait(_nativeMonitor);
}

Expand All @@ -54,6 +60,10 @@ private bool WaitCore(int timeoutMilliseconds)
return true;
}

#if FEATURE_WASM_MANAGED_THREADS
Thread.AssureBlockingPossible();
#endif

return Interop.Sys.LowLevelMonitor_TimedWait(_nativeMonitor, timeoutMilliseconds);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ await executor.Execute(async () =>
[Theory, MemberData(nameof(GetTargetThreadsAndBlockingCalls))]
public async Task WaitAssertsOnJSInteropThreads(Executor executor, NamedCall method)
{
using var cts = CreateTestCaseTimeoutSource();
CancellationTokenSource? cts = null;
radekdoulik marked this conversation as resolved.
Show resolved Hide resolved
Thread.ForceBlockingWait((_) => cts = CreateTestCaseTimeoutSource(), null);
await executor.Execute(Task () =>
{
Exception? exception = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ public class NamedCall
sem.Wait(cts.Token);
} catch (OperationCanceledException) { /* ignore */ }
radekdoulik marked this conversation as resolved.
Show resolved Hide resolved
}},
new NamedCall { Name = "CancellationTokenSource.ctor", Call = delegate (CancellationToken ct) {
using var cts = new CancellationTokenSource(8);
}},
new NamedCall { Name = "Mutex.WaitOne", Call = delegate (CancellationToken ct) {
using var mr = new ManualResetEventSlim(false);
var mutex = new Mutex();
var thread = new Thread(() => {
mutex.WaitOne();
mr.Set();
Thread.Sleep(50);
mutex.ReleaseMutex();
});
thread.Start();
Thread.ForceBlockingWait((_) => mr.Wait(), null);
mutex.WaitOne();
}},
};

public static IEnumerable<object[]> GetTargetThreadsAndBlockingCalls()
Expand Down
Loading