- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
[wasm][mt] throw from blocking wait on JS interop threads #97052
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
Changes from all commits
b049c6a
              150a177
              a88e493
              61b797c
              1ed5faa
              9d24021
              70ad3a6
              dbe7c4c
              eb995fb
              5887749
              4009ae3
              dd82372
              e77f866
              5c95514
              e1af48a
              9ec32c1
              91508ac
              4f74e02
              00e6b4b
              1dd3af2
              5643036
              7f067df
              d3a68e9
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -49,6 +49,7 @@ public static JSSynchronizationContext InstallWebWorkerInterop(bool isMainThread | |
| var ctx = new JSSynchronizationContext(isMainThread, cancellationToken); | ||
| ctx.previousSynchronizationContext = SynchronizationContext.Current; | ||
| SynchronizationContext.SetSynchronizationContext(ctx); | ||
| Monitor.ThrowOnBlockingWaitOnJSInteropThread = true; | ||
|  | ||
| var proxyContext = ctx.ProxyContext; | ||
| JSProxyContext.CurrentThreadContext = proxyContext; | ||
|  | @@ -215,7 +216,10 @@ public override void Send(SendOrPostCallback d, object? state) | |
| Environment.FailFast($"JSSynchronizationContext.Send failed, ManagedThreadId: {Environment.CurrentManagedThreadId}. {Environment.NewLine} {Environment.StackTrace}"); | ||
| } | ||
|  | ||
| var threadFlag = Monitor.ThrowOnBlockingWaitOnJSInteropThread; | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm re-thinking if this should be allowed after all. Because that could call code on the other thread, which would be long blocking. At the moment, this is necessary for the HTTP/WS clients to work across threads. But now I will change the implementation to use emscripten instead of  So I guess we merge this for now and I will improve it bit later. | ||
| Monitor.ThrowOnBlockingWaitOnJSInteropThread = false; | ||
| signal.Wait(); | ||
| Monitor.ThrowOnBlockingWaitOnJSInteropThread = threadFlag; | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be in  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll will change that on my PR #97832 | ||
|  | ||
| if (_isCancellationRequested) | ||
| { | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -9,6 +9,11 @@ namespace System.Threading | |
| { | ||
| public static partial class Monitor | ||
| { | ||
| #if FEATURE_WASM_THREADS | ||
| [ThreadStatic] | ||
| public static bool ThrowOnBlockingWaitOnJSInteropThread; | ||
| #endif | ||
|  | ||
| [Intrinsic] | ||
| [MethodImplAttribute(MethodImplOptions.InternalCall)] // Interpreter is missing this intrinsic | ||
| public static void Enter(object obj) => Enter(obj); | ||
|  | @@ -77,6 +82,12 @@ public static bool IsEntered(object obj) | |
| public static bool Wait(object obj, int millisecondsTimeout) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(obj); | ||
| #if FEATURE_WASM_THREADS | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make helper method for this and localize the message. | ||
| if (ThrowOnBlockingWaitOnJSInteropThread) | ||
| { | ||
| throw new PlatformNotSupportedException("blocking Wait is not supported on the JS interop threads."); | ||
| } | ||
| #endif | ||
| return ObjWait(millisecondsTimeout, obj); | ||
| } | ||
|  | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.