std::at_quick_exit
来自 zh.cppreference.net
| 定义于头文件 <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
|
|