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
|