Lets get started here:
- Why aren't you using std::thread?
- The function you're passing to CreateThread MUST be __stdcall (WINAPI). Microsoft goes to a lot of effort to detect when people do bad things like pass in cdecl or similar calling conventions. All that work is overhead you inherit when you do it wrong.
- Having a function called "createThreadFunction" that takes a VOID POINTER as a function parameter is just flat out wrong. Don't do this.
- bool, and std::atomic<bool> are not mutexes. You can use std::mutex if you need mutex like behavior.
- While std::atomic<bool> does enforce a memory barrier, it does not prevent multiple pieces of the same code from running at once.