Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS: missing Obj-C autorelease pool handling #58

Open
kikaxa opened this issue Feb 9, 2024 · 3 comments
Open

MacOS: missing Obj-C autorelease pool handling #58

kikaxa opened this issue Feb 9, 2024 · 3 comments

Comments

@kikaxa
Copy link

kikaxa commented Feb 9, 2024

Most functions end up using native apis which create autorelease objects.
These objects would be effectively "leaked" if run through async++.

The thread pool/loop needs local per-iteration pool to match user expectations(or lack of).

sample Qt pool handling:

#ifdef __APPLE__
// Use the direct runtime interface to manage autorelease pools, as it
// has less overhead then allocating NSAutoreleasePools, and allows for
// a future where we use ARC (where NSAutoreleasePool is not allowed).
// https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support
extern "C" {
    void *objc_autoreleasePoolPush(void);
    void objc_autoreleasePoolPop(void *pool);
}
    #define AUTORELEASE_THREAD_GUARD() auto poolDone = ScopedDefer([pool = objc_autoreleasePoolPush()](){ objc_autoreleasePoolPop(pool); });
#else
    #define AUTORELEASE_THREAD_GUARD()
#endif
@kikaxa
Copy link
Author

kikaxa commented Feb 15, 2024

due to the need to also cover inline and thread schedulers, the patch is really invasive and must be done at the loop level of thread pool.
one can find the changes at https://github.com/kikaxa/asyncplusplus

@Amanieu
Copy link
Owner

Amanieu commented Feb 15, 2024

@kikaxa I'm no longer actively maintaining this project. Would you like me to add you as a member so you can merge PRs and commit directly?

@kikaxa
Copy link
Author

kikaxa commented Feb 16, 2024

@kikaxa I'm no longer actively maintaining this project. Would you like me to add you as a member so you can merge PRs and commit directly?

I can do that, except my requirements are a bit different to original ones.
As example, i no longer target c++11, with 14-17 being preferred and 20 used in many places. As such, i fear i may miss something and make it worse for whatever users actually want older standards working. (some CI additions might be able to help that)
(There are also ideas to try integrating coroutines and newer standards really simplify some template magic)

Again, im not very active on projects outside my work so probably only minimal support and trivial changes are expected.

Maybe, current code can be stabilised as tag/release and a new "experimental" branch can be started that has less requirements

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

No branches or pull requests

2 participants