名稱空間
變體
操作

std::at_quick_exit

來自 cppreference.com
< cpp‎ | utility‎ | program
 
 
 
 
定義於標頭檔案 <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 文件at_quick_exit