Thread falls without coredump - c++

I have multi-thread application, in which main thread falls on some event. Thread falls on SIGSEGV signal. Other threads continue work. My question is how to dig maximum information about failed thread to analyse it later? Starting with the question of how to find out which of the threads fell.
Really it is actual ussie which arose when working with qt 4.7 signal/slot system + webview widget. It's interesting that on version 5 everything is fine.
I will be happy for any idea. I'm working on ubuntu, qt project.

Related

Cross thread call a.k.a run on main/UI thread from other thread without dependencies needed

I'm on some c++ mobile product, but I need my apps main thread is still running without any blocking when doing some heavy work on the background thread and run back on main thread. But I realized there is no runOnMainThread/runOnUIThread in c++ thread api. I trying to figure it out the issue and found that need to depend library, or create your own thread event queue. Although it is good, but i am thinking to have a behavior which can runOnUIThread.
How it does not work: the mentioned library creates a timer, installs a SIGALRM signal handler and dispatches queued tasks when signals are fired. This allows tasks being processed on the main thread even when it is busy. However POSIX permits only a small set of async-signal-safe functions to be invoked inside of signal handler. Running arbitrary с++ code inside of signal handler violates that restriction and leaves application in hopelessly doomed state.
After some research and development, I've created a library called NonBlockpp
it is a small c++ library to allow c++ mobile application able to process the heavy and time consuming task on background and back to Main thread again, It’s been tested and fired the main thread event.
It also allow to save the tasks and fire them later, all the task has no blocking each other and thread safety.
How it works:
If you found any query or suggestion, please don't hesitate to raise an issue and we can discuss it together.
The project has rectify from signal to pollEvent due to signal handler might not be safe to use.
Please take a look the new changed.
NonBlockpp
Usage

How to program to prevent the Windows "Not Responding" dialog [duplicate]

This question already has answers here:
Avoiding "(Not Responding)" label in windows while processing lots of data in one lump
(11 answers)
Closed 7 years ago.
When an application fails to be responsive for 5 seconds (source), Windows can display "(Not Responding)" in the title bar and in some cases show a "not responding" dialog:
Ideally, the 5+ second execution should not block the main/event-processing thread, but is there a simple (e.g. 1 liner for MFC C++) way to communicate to Windows that the main thread is busy and shouldn't be treated as a "Not Responding" application to be closed? Is the quickest hack to simply periodically call peak PeekMessage with PM_NOREMOVE?
There really are no hacks to solve this. Any monkeying about with the message pump can lead to all manner of disaster, especially with COM and other system message processing.
Don't hold up the main thread.
Move the longer running tasks to a background or worker thread and either poll a future for completion or have the thread post a message back to the GUI to signal it is complete and then retrieve the result required.
In Windows 3.1 world all those eons ago, the answer was to divide your work into short-duration chunks, run the chunks in your window's message procedure and go from chunk to chunk by calling PostMessage.
Nowadays you update the window to show that the work is in progress, spawn a thread and call some PostMessage equivalent at the end of the thread so that your window can update itself back and show the results.
No, there's no quick hack, because your app is indeed not responding if you use the main thread like that.

SFML Threading causes errors on linux XInitThreads not called

I'm using sf::Threads in my program and I have it running in windows, but now I'm porting it over to windows. I already have the build target made and it successfully compiles, and runs right up until I try to launch the game, which uses threads. Then my objects are successfully constructed, but then it says that:
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
NumberHunterGame: xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
I'm using SFML 2.1 in my program grabbed directly from the Fedora repos.
I was reading a forum thread about passing my sf::RenderWindow as a pointer to my rendering thread func, but I don't think that will make any difference as I made my sf::RenderWindow instance a global. I tried calling XInitThreads() at the beginning of main, but that causes more problems then it solves.
The whole file is available here: https://github.com/HSchmale16/NumberHunterGame/blob/master/main.cpp
Edit: I've been asked about how I have the threads set up and this is the general design.
I create the sf::RenderWindow in the main thread then deactivate in the main thread then launch the rendering thread. After that I launch the game event handling thread. The only thing the main thread handles is the window events, so it should be thread safe. The SFML docs say that I can handle the window events in the main thread while using another thread to render.

SDL2 running inside a non-main thread

Having some confusion over what counts as the "Main" thread in this situation.
I have QT running in my first thread which is blocking. I want to run SDL2 in a secondary thread, with all calls and initilisation isolated to this thread.
Will this allow SDL2 to run correctly and stable as the Documentation states it needs to be in the main thread? Also this question SDL2 two windows in different threads states you can't use certain SDL2 functions outside the "main" thread.
In this case is the main thread, as far as SDL2 is concerned, the first thread containing QT, or the second thread SDL2 was initilised in?
This is just a guess, but in linux the concept of a "main thread" is the first thread in a process. Here's how to see if a thread is the main thread: Check if current thread is main thread
So to answer your question, you can't have QT running as the first thread and SDL2 running as the second. You'll either need:
Two processes. Then, each is running a main thread
Run SDL as the first process (the main thread) and QT as a subthread (if QT allows for this)

QProcess: Destroyed while process is still running

I am using Qt for developing a custom control interface to xmgrace, a 2D plotting library.
I have 3 components in my project:
A GUI made in Qt
A QThread which runs some shared object code from C in a background thread.
An xmgrace window connected to both the above using a pipe. (Using the grace_np library)
Communication from (1) --> (2) is done by changing status of some global variables declared in the shared object code.
Communication from (1) --> (3) & (2) --> (3) is using built in functions provided by the grace_np library.
Now, communication from (2) --> (1) is what is causing problems. I tried 2 possible ways I could think of:
a) Declaring a shared object in Qt code which emits a Qt Signal and is called within the C code.
b) Returning from the thread and using the return value to perform some operation and then restart the thread.
Both these methodologies have given unreliable results. My GUI gets stuck/causes segmentation fault and I get the message:
QProcess: Destroyed while process is still running
I am not using the QProcess class anywhere in my code. So this has become a mystery.
Please provide some info on what could be the possible causes for this.
PS: The pipe to (3) is one way and is required that way only.
Edit 1:
FYI I'm using Qt 4.2, So I can't use the QObject approach and then use a movetothread()
I'm sorry for not putting the code, as I can't due to company policies and also because I don't know what to put (Its too huge). The shared c code is 400k+ lines
I believe I have found the culprit to my problem. It seems that using the class QMessageBox is causing this problem. I was initially using static function of QMessageBox. Now I have tried declaring it over both the stack and the heap, but the problem still persists.
But I have found that removing all calls to QMessageBox from my code solves the problem.
But then the problem now is, how do I show messages?
I am just speculating here, but is it possible that the modal nature of QMessageBox is blocking the pipe existing between my program and xmgrace and subsequently causing it to quit? Then creating a custom QMessageBox (non modal) might solve this issue.
Edit 2:
I'm not calling the QMessageBox from the worker thread. Plus the way I'm using the worker thread, it never returns unless I close the program. To give an idea my QThread::run function is of the form:
QThread_Object::run()
{
c_init();
c_main();
}
where c_init & c_run are functions linked from shared c code. So it is impossible to call a QMessageBox from within these directly.
For now I'm planning on doing away with the QMessageBox and using the QMainWindow status bar instead. But then it doesn't give the entire functionality. I suppose this could be a bug in Qt 4.2
Edit 3:
I mentioned earlier that communication from (2) --> (1) was what was causing problems. Now I have done away with this communication completely and have discovered more precisely that the problem is caused by invoking QMessageBox anytime after starting the worker thread. Earlier the communication mentioned above was causing Qt to emit a signal indirectly and invoke a QMessageBox which I believe was the culprit.
Edit 4:
Ok, I forgot to mention the biggest mystery surrounding this problem since the beginning. I basically work(Place A) via ssh on a workstation(Place B) on which I code and run this program.
B is connected on 2 physical networks. A is connected to B through Network 1. Now this problem has never occured while working from my terminal at A (ie on ssh via Network 1). But it consistently occurs when I access B directly or through ssh over Network 2. Please note that every time the code is executed on B only. Both these networks are used by hundereds.
Edit 5
Finally, I have solved my problem by sub-classing QDialog and making a custom MessageBox as I don't really require the extended functionality of QMessageBox. I still don't know what precisely within QMessageBox was causing the problem. I suppose some bug within Qt which will always remain a mystery.
Since there's no code I'm shooting in the dark a little here, but it sounds like your QProcess was created on the stack, intentionally or not, or your QThread is getting destroyed prematurely. I'd put money on your QThread objects being launched incorrectly. It's hard to blame you since the documentation is (or was until recently) screwy. Consider reading this thread and this thread and don't sub-class QThread at all.
Edit:
If QMessageBox is your culprit, then I'm guessing that you're displaying it from the child thread. From the documentation:
In GUI applications, the main thread is also called the GUI thread
because it's the only thread that is allowed to perform GUI-related
operations.
There are several ways to display messages from a child thread. Personally, I use qt's error reporting scheme and redirect qCritical, qDebug, etc to stderr. Another easier way to do it would be for you to emit a QString signal from your worker thread that's caught by your GUI thread, which then displays/collects the error. I like to have my MainWindow collect the errors and then display them all at once when the worker thread finishes.
Edit 2:
Since the problem seems to be QMessageBox being modal (i.e., blocking your main thread while the worker thread moves forward), you can easily solve this by using QMessageBox in its non-modal modes. Simply pass 0 as the parent widget in the QMessageBox constructor/static function. Processing will continue without waiting for the user to exit the window--this might also result in multiple message boxes being open at the same time. If that helps you avoid the error, go over your code carefully to make sure the windows are properly destroyed after closing.