std::at_quick_exit
来自 cppreference.cn
定义于头文件 <cstdlib> |
||
int at_quick_exit( /*atexit-handler*/* func ) noexcept; int at_quick_exit( /*c-atexit-handler*/* func ) noexcept; |
(1) | (自 C++11 起) |
extern "C++" using /*atexit-handler*/ = void(); extern "C" using /*c-atexit-handler*/ = void(); |
(2) | (仅为演示目的*) |
注册函数 func
(所指向的函数) 以在快速程序终止时调用 (通过 std::quick_exit)。
从多个线程调用此函数不会导致数据竞争。实现保证支持至少注册 32 个函数。确切的限制是实现定义的。
注册的函数不会在正常程序终止时被调用。如果需要在那种情况下调用函数,则必须使用 std::atexit。
内容 |
[编辑] 参数
func | - | 指向在快速程序终止时被调用的函数的指针 |
[编辑] 返回值
0 如果注册成功,则为零值,否则为非零值。
[编辑] 注解
这两个重载是不同的,因为参数 func
的类型不同(语言链接 是其类型的一部分)。
[编辑] 示例
运行此代码
#include <cstdlib> #include <iostream> void f1() { std::cout << "pushed first" << std::endl; // flush is intentional } extern "C" void f2() { std::cout << "pushed second\n"; } int main() { auto f3 = [] { std::cout << "pushed third\n"; }; std::at_quick_exit(f1); std::at_quick_exit(f2); std::at_quick_exit(f3); std::quick_exit(0); }
输出
pushed third pushed second pushed first
[编辑] 参见
导致异常程序终止(不清理) (函数) | |
导致正常程序终止并清理 (函数) | |
注册一个函数,以便在调用 std::exit() 时调用 (函数) | |
(C++11) |
导致快速程序终止,但不完全清理 (函数) |
C 文档 关于 at_quick_exit 的文档
|