My recommendations would be:
1. Use a debugger to inspect the objects/variables/addresses involved in the crash and see if what is actually happening matches your expectations of what
should happen.
2. Turn your compilers warning level up and fix the issues it points you at.
3. Use tools like
address sanitizer and
Valgrind to detect bugs in your code.
4. Stop using threads. Threads are
hard to get right and introduce a huge amount of complexity and potential problems and you don't strike me as nearly experienced enough to be playing around with such advanced tools.
5. Read up (more) on C++ - I get the impression that things like object lifetimes, RAII and similar are foreign to you and may be the root cause of your problems.