macosx about atexit and subthreads

8 篇文章 0 订阅
3 篇文章 0 订阅

you can use the api atexit to register when the thread is going to exit, the api is from stdlib.h.


1.here is personal thoughts after some test and debug:

When main-thread executing atexit, other subthreads can keep on running. After main-thread finish atexit, subthreads those are still running will be in dangerous state: they may soon be terminated by system, without finishing their jobs.


2.how to test:

You can create subthreads and sleep for a while, register a function to the api atexit in main-thread. They won't start terminating sleeping until after the function is done.


3.where is the thoughts from:

https://www.openssl.org/docs/man1.1.1/man3/OPENSSL_thread_stop.html#NOTES

On Linux/Unix where OpenSSL has been loaded via dlopen() and the application is multi-threaded and if dlclose() is subsequently called prior to the threads being destroyed then OpenSSL will not be able to deallocate resources associated with those threads. The application should either call OPENSSL_thread_stop() on each thread prior to the dlclose() call, or alternatively the original dlopen() call should use the RTLD_NODELETE flag (where available on the platform).

Under windows, after FreeLibrary(.dll) in main-thread, while calling ~dllModule(){..stopAndWaitThreadPool()} in main-thread, sub-threads can be terminated, leaving resources not recycled in time, resulting in something such as blocking in main-thread in the api stopAndWaitThreadPool()!!! So I guessed that it could be the same under macosx.

However!!! Those subthreads is still running while calling ~dylibModule(){..stopAndWaitThreadPool} and finish jobs before the api stopAndWaitThreadPool! And then I test and debug.


you can read more info about how to call the api OPENSSL_thread_stop
https://blog.csdn.net/newmandirl/article/details/80081210

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值