Skip to content

StdThread Panic while use load-dynamic and ThreadManager in Windows #441

Closed

Description

@greenhat616

When enabled load-dynamic feature, loaded onnxruntime from a dylib, and use with_thread_manager to customize thread pool, causing a panic from rust thread.

  • Possible stopped the thread by onnxruntime
Panic payload: threads should not terminate unexpectedly
Panic location: Some(
    Location {
        file: "C:\\Users\\a6320\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib/rustlib/src/rust\\library\\std\\src\\thread\\mod.rs",
        line: 1767,
        column: 14,
    },
)

I noted that the lastest build, likely, not provide a dylib.

Here was a prebuilt windows onnxruntime 1.22.1 dylib, with xnnpack, openvino, cuda, directml enabled.

Activity

  1. self-assigned this
    on Jul 22, 2025
  2. added
    bug
    on Jul 22, 2025
  3. decahedron1 commented on Jul 23, 2025

    @decahedron1
    Member

    Hmm, I can't reproduce this with a simple thread manager that uses std::thread::spawn & join(). Could you share your ThreadManager implementation?

  4. greenhat616 commented on Jul 23, 2025

    @greenhat616
    Author

    I updated a reproduce demo at: https://github.com/greenhat616/onnx-reproduce

    I used the same ThreadManager impl from examples: https://github.com/greenhat616/onnx-reproduce/blob/main/src/pool.rs

    • I just tested in Windows, and not sure whether exist same issue in Linux.

    You can simplely test the case by:

    cargo run -- -e cpu 
    cargo run -- -e directml -m fp16
    Image
  5. changed the title [-]Panic while use `load-dynamic` and `ThreadManager`[/-] [+]StdThread Panic while use `load-dynamic` and `ThreadManager` in Windows[/+] on Jul 23, 2025
  6. decahedron1 commented on Jul 23, 2025

    @decahedron1
    Member

    Thanks, was able to reproduce. It seems to only happen when the thread manager is used in a global thread pool. Evidently, there's some kind of race condition where something is being unloaded before the threads are joined. That's annoying 😕

  7. added a commit that references this issue on Sep 1, 2025
    317be20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions