-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Blazor client developers can use Parallel.For in their applications to share more code with server #43411
Comments
I think this is by design -- Roslyn uses mechanisms that rely on mutexes, and those aren't supported on Blazor. |
@danmosemsft But why would it work on first page load? Also to note it works when you close the original tab and create a new one. |
I am guessing that if no task is already in progress, it has a special path that does not bother to check the mutex. |
Although There two different solutions I can think of
@jeffhandley @buyaa-n I'm concern that #43363 did catch this issue. Could you please investigate why? |
Tagging subscribers to this area: @tarekgh |
Tagging subscribers to this area: @tarekgh |
@marek-safar I think it would be beneficial to go with the first option (of course I would say that :) ). The roslyn api is so close to working perfectly under wasm and I think a significant number of users are using this api within the browser. Would marking the API as unsupported mean even the features that were working wouldn't work? Perhaps adding an option as an input parameter to disable multithreading could also work? |
Marking API as unsupported would push the responsibility not to call this API to developers which is not a great option in this case (everyone you'd need to think about the else case in |
If Environment.ProcessorCount == 1, Parallel.For should not end up using other threads. You see otherwise? |
Oops, nevermind, I was thinking of PLINQ. It can make sense for Parallel.For to use multiple threads even on a single core. The difference with wasm/blazor is it's not just single core but also single thread. |
Heh, me too. Tweaked my comment to focus on a single thread environment |
I agree we should fix |
I suspect this is related to #2078 as well, and that a fix to that would make this error go away without further changes to Parallel.For to try to special-case a system that only ever has a single thread. |
Do we have API to detect whether only 1 thread is possible? ( |
Nope |
You can always try/catch PNSE. |
What about ThreadPool.GetMaxThreads? |
In a console app, as an example, if GetMaxThreads said there was one worker thread, that still means the app has at least two threads on which it can execute code: the main thread and that single thread pool thread. With Blazor/wasm, they're one in the same. |
For #38690 what we did was add an internal bool |
The app can have 100 threads but if TP is limited to single thread System.Threading.Tasks.Parallel.For should probably be optimized for sequential execution |
Parallel.For uses the current thread. If you run it from the main thread and there's also a thread pool thread, it should use both. |
Hey does anyone have a rough ETA / update for this? Will it be expected to be fixed for main release coming up? |
@andersson09 if you can easily create a sample that failed with rc2 and the older roslyn I would definitely still be interested in looking at it. This path has changed a little in roslyn but not in a way that would obviously resolve what appeared to be the issue here. |
@lewing presumably this should also be trigger by some of the existing tests |
It almost sounds like you should just support this instead: |
Our issue is exactly the opposite of @andersson09's, and happens in a different place, but seems to have the same root cause. Our call to The solutions proposed above to "fix"
|
Guys, could you please help me find out how this issue was fixed? I sense this was fixed specifically and only in Blazor. My non-blazor wasm app has the same issue as OP. If I move the code to a blazor app it works just fine. In my non-blazor wasm app I get the same error "Cannot wait on monitors on this runtime.". Was the issue addressed in Roslyn itself? Where's the fix? |
@lewing ? |
The issue is not yet fixed. It's planned for .NET6 release with Priority 2 (see the labels). |
@marek-safar @lewing It most certainly is fixed in Blazor .NET 5, because you can use Roslyn. I've checked it, it does use Parallel.For inside GetDiagnostics (concurrentBuild option on CSharpCompilationOptions is true). The easiest way to reproduce this without Roslyn is to call this C# code anywhere from js "Parallel.For(0, 10, i => Console.WriteLine(i));". It works only in Blazor apps. |
Description
Hi,
So the Roslyn compiler is kind of working in blazor wasm with the latest version (3.8.0-4.final) which is great! Appears the hashing issues are fixed. However, now I find there is a strange bug whereby I receive a multi threading exception under the following scenario:
Strangely it works if I close the original tab and open a new one.
Thanks
Configuration
Regression?
Last time Roslyn was working in the browser was with Blazor Webassembly 3.2.1 and Microsoft.CodeAnalysis 3.6.0
Other information
The text was updated successfully, but these errors were encountered: