有几个教程解释了 atexit()
函数的用法,例如:
http://linux.die.net/man/3/atexit
例子在一个简单易懂的main函数中给出。但是,我在我的程序中创建了一个共享库,并提供了一些可以从其他程序导出的函数。当另一个程序卸载我的共享库时,我想停止共享库中的一些线程。如何在我的共享库实现中使用 atexit()
而不强制用户调用某些函数,例如destroy()
最后?
提前致谢。
最佳答案
Since glibc 2.2.3, atexit() (and on_exit(3)) can be used within a shared library to establish functions that are called when the shared library is unloaded.
另一方面,为什么不创建一个全局范围的对象并在其析构函数中执行整理代码?
关于c++ - atexit() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10702980/