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

Johnathan Waring 21 Reputation points
2021-11-10T15:29:07.28+00:00

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.

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,376 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 54,866 Reputation points
    2021-11-10T15:45:03.71+00:00

    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.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Johnathan Waring 21 Reputation points
    2021-11-10T15:47:41.743+00:00

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

    Cheers,
    John.

    0 comments No comments

  2. Bruce Barker 801 Reputation points
    2021-11-10T16:28:35.21+00:00

    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.