Receving Seg Fault in Qthread when SIGINT Signal arrives



  • For my c++ application i have created 4 qthread as follows:

    main() {

    register_sig_handler();

    a.start();
    b.start();
    c.start();
    d.start();

    a.wait();
    b.wait();
    c.wait();
    d.wait();

    Now In my "register_sig_handler" function, I have register signal as follows:
    signal(SIGINT, signal_handler);

    Now whenever I provide SIGINT using ctrl + c using keyboard. My code goes into signal handler but at the end it shows Segmentation fault(core dumped). As I ran code with gdb It looks like, error comes because of wait. So How can remove Seg fault?

    Thanks In advance.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What you are doing in your threads ?

    Can you share the stack trace you get ?



  • Sorry For Late Reply

    Here Is BackTrace of My app after giving SIGINT

    Program received signal SIGINT, Interrupt.
    0x76beef38 in pthread_cond_wait () from /lib/libpthread.so.0
    (gdb) bt
    #0 0x76beef38 in pthread_cond_wait () from /lib/libpthread.so.0
    #1 0x76c96f68 in QWaitCondition::wait(QMutex*, unsigned long) () from /usr/lib/libQt5Core.so.5
    #2 0x76c9600e in QThread::wait(unsigned long) () from /usr/lib/libQt5Core.so.5
    #3 0x0000e6cc in main (argc=1, argv=<optimized out>) at ../ccms_meter/src/main.cpp:44


  • Lifetime Qt Champion

    That doesn't explain what your threads are currently doing.

    Also, what do you do in your signal handler ?



  • In my thread, i have socketio event handlers and i am sending and receiving events.
    In signal handler, I have only print statement which will print encountered signal number. If I doesn't call handler, than there is no issue.


  • Lifetime Qt Champion

    Can you share your code ?



  • My application has 16 files covering 4 threads. So it will be not feasible to share code. For that I have mentioned pseudo code, As per my understanding Segmentation fault is not coming because of whatever written in thread. It is coming because of thread wait condition. So is it appropriate to use thread.wait with signal handling function?


  • Moderators

    @mbajaria said in Receving Seg Fault in Qthread when SIGINT Signal arrives:

    My application has 16 files covering 4 threads. So it will be not feasible to share code. For that I have mentioned pseudo code

    Can you produce a small, compilable example that demonstrates this issue?


  • Qt Champions 2016

    @mbajaria said in Receving Seg Fault in Qthread when SIGINT Signal arrives:

    Here Is BackTrace of My app after giving SIGINT

    What is the backtrace at the point when the SIGSEGV is being raised?


Log in to reply