1
Window / Re: Multi-threading tutorial example does not work
« on: July 08, 2018, 09:08:26 pm »
Upon further examination and debugging, I have found the following issues:
When adding mutexes to stop race condition, the condition improves. In my previous attempt I had forgotten to unlock the mutex after exiting loops. Although this lead to the program working as expected, it still crashed after a couple of seconds running. The error suggested the use of XInitThreads.
The program is now running as expected after the following steps:
I installed the libX11 package (Fedora):
Added the library to the code
Added the XInitThreads() function call before creating a new thread
Compiled with the additional flag
This seems to have worked, even after I removed all the mutexes, although I am not entirely sure why.
I will do some further research on the what XInitThreads does and will report back with further details.
When adding mutexes to stop race condition, the condition improves. In my previous attempt I had forgotten to unlock the mutex after exiting loops. Although this lead to the program working as expected, it still crashed after a couple of seconds running. The error suggested the use of XInitThreads.
The program is now running as expected after the following steps:
I installed the libX11 package (Fedora):
Quote
sudo dnf install libX11-devel.x86_64 -y
Added the library to the code
Quote
#include <X11/Xlib.h>
Added the XInitThreads() function call before creating a new thread
Quote
int main() {
// ...
XInitThreads();
std::thread eventThread(/*..*/);
// rest of code...
}
Compiled with the additional flag
Quote
-lX11
This seems to have worked, even after I removed all the mutexes, although I am not entirely sure why.
I will do some further research on the what XInitThreads does and will report back with further details.