atexit() 函数 [英] atexit() function

查看:66
本文介绍了atexit() 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几个教程解释了 atexit() 函数的用法,例如:

There are several tutorials which explains the usage of atexit() function such as:

http://linux.die.net/man/3/atexit

示例在易于理解的主函数中给出.但是,我在我的程序中创建了一个共享库,并且我提供了一些要从其他程序导出的函数.当另一个程序卸载我的共享库时,我想停止共享库中的一些线程.如何在我的共享库实现中使用 atexit() 而不强制用户调用某些函数,例如destroy() 最后呢?

The examples are given in a main function which can be understood easily. However, I am creating a shared library in my program and I provide some functions to be exported from other programs. I want to stop some threads inside shared library when another program unloads my shared library. How can I use atexit() in my shared library implementation without forcing users to call some function e.g. destroy() at the end?

提前致谢.

推荐答案

文档 指出:

从 glibc 2.2.3 开始,atexit()(和 on_exit(3))可以在一个共享库建立共享时调用的函数库已卸载.

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.

另一方面,为什么不创建一个全局范围的对象并在其析构函数中执行整理代码?

On the other hand, why don't you just make an object of global scope and perform your tidy up code in its destructor?

这篇关于atexit() 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆