question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

initThreadPool freezing after call

See original GitHub issue

I’m trying to make the basic example with the sum function work

#[wasm_bindgen]
pub fn sum(numbers: &[i32]) -> i32 {
    numbers.par_iter().sum()
}

but every time when JS hit the funcion initThreadPool(even with the init function working correctly), he’s freezing, I have tried in two different ways, first

init().then(_ => {
    initThreadPool(navigator.hardwareConcurrency).then(_ => {
        sum(new Int32Array([1, 2, 3]))
    })
})

and

init().then(_ => {
    initThreadPool(navigator.hardwareConcurrency);
    sum(new Int32Array([1, 2, 3]));
})

but with that last way, I always get that error: “panicked at ‘The global thread pool has not been initialized.: ThreadPoolBuildError { kind: IOError(Error { kind: Unsupported, message: “operation not supported on this platform” }) }’”, and after a few days I still have no idea what it could be

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
RReversercommented, Dec 15, 2021

@ranis-junior Wait a second, so you’re trying to use wasm-bindgen generated code directly from HTML, aka from the main thread? Unfortunately that won’t work due to Wasm limitations intended to avoid blocking the main thread.

Please check the Caveats section of the docs as well as how the demo does it - you must do all the work in a dedicated Worker.

Even if you don’t use Comlink, the minimal example should be more like:

  1. worker.js:
import init, {sum, initThreadPool} from "/static/pkg/sum.js";

init().then(_ => {
    initThreadPool(navigator.hardwareConcurrency).then(_ => {
        let result = sum(new Int32Array([1, 2, 3]))
        console.log(result)
    })
})
  1. index.html:
<script type="module">
new Worker(new URL('worker.js', import.meta.url), { type: 'module' });
</script>

It’s surprising that you didn’t see an error message in the Console, both Chrome and Firefox should complain when you’re trying to use Wasm threads from the main browser thread.

0reactions
RReversercommented, Dec 16, 2021

Glad it worked!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix an Android device that freezes or won't respond
Try the following steps if your phone: Freezes Stops responding Is stuck with the screen on After each step, restart your phone to...
Read more >
What To Do if Your Phone Keeps Freezing - Progressive
When a phone freezes can be a hint as to why it's freezing. Try to isolate when the issue occurs so you can...
Read more >
c# - App freezes after Dispatcher.Invoke - Stack Overflow
I have this application that freezes when calling the dispatcher.invoke for any control. When i Call the Dispatcher in radiobutton, Grid, ...
Read more >
Why is my phone acting sluggish and freezing? - HTC Support
When a smartphone is handling too many processes or the RAM is full, the phone's performance can suffer, causing it to lag, run...
Read more >
Crashing, freezing, or unexpectedly restarting troubleshooting
Crashing, freezing, and restarting are usually signs of a software or app problem. This means your device isn't broken, but probably needs some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found