Guard your render thread's quit flag somehow, or use atomic_flag or condition_variable. You're modifying and checking it in two diff threads. Also, read up on RAII, it'll save you. the rendy object lifetime destructor happens after SDL_Quit(). This is probably fine with SDL, but be aware that improper ordering of destruction can result in memory leaks and crashing with other libs and even in your own code. Just some tips :)
EDIT: Oh yeah, you don't need "this->" everywhere. You only need it for "this->window = window;" because of the name clash.
EDIT2: SDL_DestroyWindow needs to be called on the same thread that created it. I think this is a platform-specific limitation.
EDIT3: I was suspecting that there was another issue with the SDL state access between threads but I could not remember the rules for it. /u/nope_dot_avi's comment is correct, the unprotected window data is accessed by 2 threads.
Anyone wishing to dive into concurrency should Read this book
Cool. But I still would like to master atomics. Do you know a good read about this topic. A book maybe? I have a book regarding multithread programming. This one : https://www.amazon.com/C-Concurrency-Action-Practical-Multithreading/dp/1933988770.
I had to rest between some chapters, because overloads my brain pretty fast. 😆
Personally I think it is best to learn c++ by reading books.
In this case the book would be: https://www.amazon.de/C-Concurrency-Action-Anthony-Williams/dp/1933988770
It starts slow with basic multi threading later explains atomics, memory model and other more advanced things with plenty of examples.
Would you recommend Effective Modern C++? I've been writing in C++ for 2-3 years now, and I've already read "Effective C++" and "More Effective C++" cover-to-cover, so I wouldn't consider myself a newbie... mainly, I'm just looking to learn multithreading, and I was considering a book such as this one.
Please read: https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.4
It specifically talks about compiler reordering, that fact that all variable bar locals are shared, and explicitly synchronisation actions.
But this is the Java memory model; which is an abstraction, implementations then implement this model on their hardware.
A good discussion on why it’s needed is the old double checked locking issue: https://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
A good text on the multithreading is C++ Concurrency in Action: Practical Multithreading https://www.amazon.co.uk/dp/1933988770/ref=cm_sw_r_cp_api_glc_fabc_E0Y0FP64Z9ESHS90Q8GA - not Java, but goes into a lot more detail than plenty of the Java texts.
This: A Primer on Memory Consistency and Cache Coherence (Synthesis Lectures on Computer Architecture): Written by Daniel Sorin, 2011 Edition, Publisher: Morgan & Claypool Publishers [Paperback] https://www.amazon.co.uk/dp/B00SLW1XGE/ref=cm_sw_r_cp_api_glc_fabc_358KSX2EKZP1DGNHRWKJ
Is a great text on what’s actually happening.
Other book:
Other lib:
Other tools (free for open source):
Continuous build + test
static analysis