C++ Reference: Standard C++ Library reference: C Library: cstdlib: at_quick_exit

C++官网参考链接:https://cplusplus.com/reference/cstdlib/at_quick_exit/

函数 
<cstdlib>
at_quick_exit
C11
int at_quick_exit (void (*func)(void));
C++11
extern "C" int at_quick_exit (void (*func)(void)) noexcept;
extern "C++" int at_quick_exit (void (*func)(void)) noexcept;
设置快速退出时执行的函数
func所指向的函数在调用quick_exit(不带实参)时自动调用。
如果对该函数的不同调用指定了多个at_quick_exit函数,则它们都将以相反的顺序执行。
如果在at_quick_exit中注册的函数在被quick_exit调用时抛出了一个异常,而它没有为该异常提供处理程序,则会自动调用terminate(C++)。
注意,函数的at_quick_exit堆栈与atexit堆栈是分开的(每个函数都由不同的环境触发),但是可以将相同的函数传递给两个函数,以便在两种情况下都调用它。
特定的库实现可能会对可以注册到at_quick_exit的函数数量施加限制,但这个限制不能少于32个函数。

形参
func
函数被调用。函数不返回任何值,也不接受任何实参。

返回值
如果函数成功注册,则返回0值。
如果失败,则返回非0值。

用例
/* at_quick_exit example */
#include <stdio.h>      /* puts */
#include <stdlib.h>     /* at_quick_exit, quick_exit, EXIT_SUCCESS */

void fnQExit (void)
{
  puts ("Quick exit function.");
}

int main ()
{
  at_quick_exit (fnQExit);
  puts ("Main function: Beginning");
  quick_exit (EXIT_SUCCESS);
  puts ("Main function: End");  // never executed
  return 0;

输出:

/* DEV-C++ ISO-C++11中没有at_quick_exit的定义,因此会出现编译错误 */

/* 官网参考答案:

Main function: Beginning
Quick exit function. */

数据竞争
同时调用这个函数不会引入数据竞争:调用在进程级别是正确同步的,但是注意到从不同的线程调用的相对顺序是不确定的。
在调用quick_exit之前没有完成的at_quick_exit调用可能不会成功(取决于特定的库实现)。

异常(C++) 
无抛出保证:此函数从不抛出异常。 

另请参考
atexit    Set function to be executed on exit (function)
quick_exit    Terminate calling process quick (function)
abort    Abort current process (function) 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
This quick reference is a condensed guide to the essential data structures, algorithms, and functions provided by the C++17 Standard Library. It does not explain the C++ language or syntax, but is accessible to anyone with basic C++ knowledge or programming experience. Even the most experienced C++ programmer will learn a thing or two from it and find it a useful memory-aid. It is hard to remember all the possibilities, details, and intricacies of the vast and growing Standard Library. This handy reference guide is therefore indispensable to any C++ programmer. It offers a condensed, well-structured summary of all essential aspects of the C++ Standard Library. No page-long, repetitive examples or obscure, rarely used features. Instead, everything you need to know and watch out for in practice is outlined in a compact, to-the-point style, interspersed with practical tips and well-chosen, clarifying examples. This new edition is updated to include all Standard Library changes in C++17, including the new vocabulary types std::string_view, any, optional, and variant; parallel algorithms; the file system library; specialized mathematical functions; and more. What You Will Learn Gain the essentials that the C++ Standard Library has to offer Use containers to efficiently store and retrieve your data Inspect and manipulate your data with algorithms See how lambda expressions allow for elegant use of algorithms Discover what the standard string class provides and how to use it Write localized applications Work with file and stream-based I/O Prevent memory leaks with smart pointers Write safe and efficient multi-threaded code using the threading libraries Who This Book Is For All C++ programmers, irrespective of their proficiency with the language or the Standard Library. A secondary audience is developers who are new to C++, but not new to programming, and who want to learn more about the C++ Standard Library in a quick, condensed manner.
C++ Standard Library Quick Reference by Peter Van Weert, Marc Gregoire 2016 | ISBN: 1484218752 | English | 206 pages PDF+EPUB This quick reference is a condensed reference guide to the essential data structures, algorithms, and functions provided by the C++ Standard Library. More specifically, this is a compact collection of essential classes and functions, used by C++ programmers on a daily basis. The C++ Standard Library Quick Reference features core classes for strings, I/O streams, and various generic containers, as well as a comprehensive set of algorithms to manipulate them. In recent years, the C++11 and C++14 standards have added even more efficient container classes, a new powerful regular expression library, and a portable multithreading library featuring threads, mutexes, condition variables, and atomic variables. Needless to say, it is hard to know and remember all the possibilities, details, and intricacies of this vast and growing library. This handy reference guide is therefore indispensable to any C++ programmer. It offers a condensed, well-structured summary of all essential aspects of the C++ Standard Library, including all aforementioned functionality. No page-long, repetitive examples or obscure, rarely used features. Instead, everything you need to know and watch out for in practice is outlined in a compact, to-the-point style, interspersed with well-chosen, clarifying examples. The book does not explain the C++ language or syntax, but is accessible to anyone with basic C++ knowledge. Even the most experienced C++ programmer though will learn a thing or two from it and find it a useful memory-aid. What You Will Learn • The essentials that the C++ Standard Library has to offer • How to use containers to efficiently store and retrieve your data • How to use algorithms to inspect and manipulate your data • How lambda expressions allow for elegant use of algorithms • What the standard string class provides and how to use it • What functionality the library provides for file and stream-based I/O • What smart pointers are and how to use them to prevent memory leaks • How to write safe and efficient multi-threaded code using the C++11 threading libraries

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_40186813

你的能量无可限量。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值