Skip to content

is exception handling thread safe? #11233

@malytomas

Description

@malytomas

I have just read this blog post:
https://brionv.com/log/2019/10/24/exception-handling-in-emscripten-how-it-works-and-why-its-disabled-by-default/
And there is a mention of a global flag variable.
Is that variable actually global and can it cause issues in multithreaded applications?

Activity

sbc100

sbc100 commented on May 23, 2020

@sbc100
Collaborator

I think its probably not thread safe today for the reason you point out.

I believe the globals in question are here:

int __threwValue = 0;

I think the solution is to make these variables into wasm globals rather than living in linear memory (similar to how we handle __stack_pointer).

kripken

kripken commented on May 23, 2020

@kripken
Member

There is also some support code in JS in src/library_exceptions.js. I believe that and extras.c is all unneeded in the new wasm exceptions support @aheejin is working on, so I hope that will be properly threadsafe?

aheejin

aheejin commented on May 24, 2020

@aheejin
Member

Yes, the wasm EH will need neither of extras.c and JS exception libraries, and I can't think of a reason why it wouldn't be thread safe.

malytomas

malytomas commented on May 28, 2020

@malytomas
Author

Thank you all for the information.

I have removed the most common place where an exception has been thrown and it significantly improved stability for the application. But I cannot replace all exceptions.

I would like to ask if there is a roadmap or a rough estimate when the new exception handling would be available? Thanks.

aheejin

aheejin commented on May 28, 2020

@aheejin
Member

We are actively working on the new EH and it is being tested and stabilized, but I think it will need several more months before being reliable enough to be tried by normal users. That being said, you can try it now by using -fwasm-exceptions flag to emcc command line (You shouldn't use -s DISABLE_EXCEPTION_CATCHING=0 with it). But it is likely that there are many bugs remaining. And currently only V8 has an experimental support for this feature among the major web VMs.

sbc100

sbc100 commented on May 28, 2020

@sbc100
Collaborator

We can possible make the current emscripten exceptions thread safe if there is strong need for it before native exception handling lands.

In the mean time we should not allow builds to use exceptions and threads at the same time.. since these are not compatible today.

malytomas

malytomas commented on Jun 9, 2020

@malytomas
Author

We can possible make the current emscripten exceptions thread safe if there is strong need for it before native exception handling lands.

I personally would prefer the effort to be put into the new native exception handling.

In the mean time we should not allow builds to use exceptions and threads at the same time.. since these are not compatible today.

Warning would have been nice, but completely failing builds is an overreaction, in my opinion.

kripken

kripken commented on Aug 25, 2020

@kripken
Member

#11518 fixed most of this, but see the comment in the code there, there remains a corner case not fully handled.

stale

stale commented on Aug 28, 2021

@stale

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

aheejin

aheejin commented on May 3, 2022

@aheejin
Member

Wasm EH proposal hasn't been fully standardized yet, but it's been implemented in Emscripten and (I believe) Safari and FireFox too, and is thread safe: https://emscripten.org/docs/porting/exceptions.html#webassembly-exception-handling-proposal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kripken@sbc100@aheejin@malytomas

        Issue actions

          is exception handling thread safe? · Issue #11233 · emscripten-core/emscripten