Skip to content

Add clear_streams API for cleanup before exit#3395

Open
zcbenz wants to merge 1 commit intoml-explore:mainfrom
zcbenz:threading-atexit
Open

Add clear_streams API for cleanup before exit#3395
zcbenz wants to merge 1 commit intoml-explore:mainfrom
zcbenz:threading-atexit

Conversation

@zcbenz
Copy link
Copy Markdown
Collaborator

@zcbenz zcbenz commented Apr 11, 2026

Windows horror story: we should not do anything complicated during thread/process teardown (i.e. in the callbacks registered by system atexit explicitly via APIs or implicitly via C++ static/thread_local keywords), joining threads would cause deadlocks, and calling any CUDA API would fail.

The solution proposed here is to just provide an API to let users invoke before thread/process exit:

    std::thread t([]() {
      auto s = new_stream(default_device());
      eval(arange(10, s));
      clear_streams();
    });
    t.join();

The API call is optional, if users don't use it the program would still work normally on macOS/Linux that everything gets synchronized and cleared implicitly by us, except for Windows where the program would crash on exit, which is actually fine for most cases.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant