question

JohnathanWaring-4575 avatar image
0 Votes"
JohnathanWaring-4575 asked JohnathanWaring-4575 commented

Blazor - Is Emcripten NuGet package intentionally missing the multithreaded libs?

Hi,

I was wondering if it is intentional that the NuGet package of Emscripten is missing the '-mt.a libs' from 'emscripten\cache\sysroot\lib\wasm32-emscripten'. I checked out the github copy emscripten and followed the steps to set it up and it's has all of the *-mt.a libs present.

Below is a sceenshot with the NuGet libs (left) and the github libs (right):
148227-screenshot-2021-11-10-152127.png

I could be missing something in the setup of my Blazor project, but it may also be a feature not supported yet. Judging by the file size differences, emscritpen is built differently for the NuGet package.

Below is what I followed to setup my Blazor client project:
https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-net-6-rc-2/#native-dependencies-support-for-blazor-webassembly-apps

I wanted to try out running C/C++ code in Blazor, which is amazing. I decided to try threaded C++ code following this post:
https://web.dev/webassembly-threads

I added the following to the Blazor Client csproj to use the C++ threads (assuming I've got this right):
<PropertyGroup>
<EmccFlags>-pthread</EmccFlags>
</PropertyGroup>

When building it produces the following error:
Exception: FROZEN_CACHE is set, but cache file is missing: "sysroot\lib\wasm32-emscripten\libgl-mt.a" (in cache root path "C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.Emscripten.2.0.23.Sdk.win-x64\6.0.0\tools\emscripten\cache")

Appreciate any information on this.
Cheers,
John.

dotnet-aspnet-core-blazor
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered

Web assembly does not support threads. Though messaging to JavaScript is async, so you can use JavaScript to implement async operations.

Note: while the blazor WASM supports the thread library, they are all just calls on the same thread, so unless they are calling JavaScript they are sync.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JohnathanWaring-4575 avatar image
0 Votes"
JohnathanWaring-4575 answered

Thanks for fast reply Bruce. I had a feeling I was mis-leading myself.

Cheers,
John.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

BruceBarker-8516 avatar image
0 Votes"
BruceBarker-8516 answered JohnathanWaring-4575 commented

currently the browser has pretty limited thread support

one thread for javascript (UI thread)
one thread per web assembly sandbox
one thread per service worker (javascript only)
one thread per web worker (javascript only)

there is a messaging library for threads to talk to each other. there is no shared memory as there is no locking.

note: just as web assembly has a project to support GC's, there is one for thread support.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Appreciate the breakdown, that's handy to know.

0 Votes 0 ·