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
基础教程推荐
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 从 std::cin 读取密码 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01