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)
Related
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
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.
Is there a way to schedule a task to be executed in the Windows main loop. I don't want to create a Windows and send an event to it.
With libdispatch I can do it with:
dispatch_async_f(dispatch_get_main_queue(), ...)
Or is there a thread in the Windows Thread Pool associated with the program's main loop?
Background:
Currently I am in the process of developing a CSP (Communicating Sequential Processing) library and most of the time tasks can be executed by the Thread Pool. But sometimes there is the need that a task is executed in the main loop. I have already a solution, if the application under Windows is a Qt application. But for non Qt applications under Windows I would like to have a solution as well.
On Windows each message loop is associated with a single thread. You can have more than one message loop per application if this is what you ask.
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.
My application uses ZModem protocol for communication.
From main thread, I am created second thread for progess bar. So, main thread is working on communication and second thread is for extra work. They are communicated through global variable.
If they are on same thread then main windows communication will be blocked.
Now, because of two thread they cannot uses DoModal() with each other.
What can i do for DoModal() this two thread or there is any option for doing it on one thread but communicating same way?
Control all windows from the main thread. Use a second thread for the communication operations.