C++ 为调试目的创建 SIGSEGV [英] C++ Creating a SIGSEGV for debug purposes

查看:12
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆