async-rs / async-rs/async-std

async-std in Windows cdylib dlls (LoadLibrary/FreeLibrary startup/cleanup)

Open
#1,059 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
4.1k
Forks
339
PR merge metrics
No merged PRs in 30d

Description

Is there a way to use async-std in Windows cdylibs that are being loaded/unloaded with `LoadLibrary`/`FreeLibrary`?

For this we'd have to ensure that before `DllMain` with `PROCESS_DETACH` returns, ***all*** threads that were spawned by async-std are no longer running. Unfortunately I do not have a clear overview over the intrinsic behaviour of async-std's thread pools, reactors (are they still a thing?) and whatnot, and the documentation was not that helpful in this particular matter.

What troubles me most are the [special rules that apply to DllMain](https://learn.microsoft.com/en-au/windows/win32/dlls/dynamic-link-library-best-practices?redirectedfrom=MSDN#general-best-practices), such as ["you cannot wait for threads to finish"](https://stackoverflow.com/questions/35828004/waitforsingleobject-for-thread-object-does-not-work-in-dll-unload/35833437#35833437).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.