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

查看:80
本文介绍了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天全站免登陆