std::at_quick_exit
来自cppreference.com
在标头 <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<<"推入第一个"<<std::endl;// 冲洗是有意的} extern"C"void f2(){std::cout<<"推入第二个\n";} int main(){auto f3 =[]{std::cout<<"推入第三个\n";}; std::at_quick_exit(f1); std::at_quick_exit(f2); std::at_quick_exit(f3);std::quick_exit(0);}
输出:
推入第三个 推入第二个 推入第一个
[编辑]参阅
导致非正常的程序终止(不进行清理) (函数) | |
导致正常的程序终止并进行清理 (函数) | |
注册将于调用 std::exit() 时被调用的函数 (函数) | |
(C++11) | 导致快速程序终止,不进行完全的清理 (函数) |
at_quick_exit 的 C 文档 |