C++ Creating a SIGSEGV for debug purposes(C++ 为调试目的创建 SIGSEGV)
问题描述
我正在开发一个无锁共享变量类,我希望能够生成一个 SIGSEGV 错误,以查看我的实现是否按计划工作.我尝试创建一个修改指针并读取它 100 次的函数.然后我在两个线程中调用这个函数并让线程在我的程序中无限运行.这不会产生我想要的错误.我该怎么做呢?
I am working on a lock-free shared variable class, and I want to be able to generate a SIGSEGV fault to see if my implementation works as I planned. I've tried creating a function that modifies a pointer and read it 100 times. I then call this function in both threads and have the threads run infinitely within my program. This doesn't generate the error I want. How should I go about doing this?
编辑我根本不处理段错误,但是如果我删除锁,它们会在我的程序中生成.我想使用无锁设计,因此我创建了一个使用 CAS 保持无锁的共享变量类.有没有办法让我有一段代码会生成段错误,以便我可以使用我的类来测试它是否解决了问题?
edit I don't handle segfaults at all, but they are generated in my program if I remove locks. I want to use a lock-less design, therefore i created a shared variable class that uses CAS to remain lockless. Is there are way that I can have a piece of code that will generate segfaults, so that i can use my class to test that it fixes the problem?
推荐答案
#include <signal.h>
raise(SIGSEGV);
将引发适当的信号.
这篇关于C++ 为调试目的创建 SIGSEGV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 为调试目的创建 SIGSEGV


- 如何对自定义类的向量使用std::find()? 2022-11-07
- Stroustrup 的 Simple_window.h 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- STL 中有 dereference_iterator 吗? 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- C++ 协变模板 2021-01-01