Skip to content

Deadlock on exit if secondary threads are writing to stdout #15186

Open
@sbc100

Description

@sbc100

When using PROXY_TO_PTHREAD and main() returns (or if a secondary pthread calls exit()),
the exitOnMainThread function is used to proxy the application exit back top the main thread and
bring down the entire application.

This means that the exit() call ends up happens during emscripten_current_thread_process_queued_calls.
However, if there are threads that are printing to stdout it will then be blocked because writing
to stdout also requires a proxied operation which requires the main thread to process queued calls
but emscripten_current_thread_process_queued_calls does not recursion.

This means that when the main thread calls fflush(0), and it tried to __lockfile(2) there is
a deadlock because the thread trying to write to stdout is already holding this lock.

This issue is responsible for the flakiness in test_pthread_c11_threads: #14579

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions