thobbsinteractive / magic-carpet-2-hd

Recode Binary code of game Magic Carpet2 to C/C++ language(remake MC2 for any platform)
GNU General Public License v3.0
27 stars 4 forks source link

Multi-threaded render has race condition issues in release code #228

Closed thobbsinteractive closed 1 year ago

thobbsinteractive commented 1 year ago

Unfortunately adding locking did not fix the issue and in Debug builds the threading works perfectly. What I am seeing is some lines not being drawn before the render moves on to the next Polygon.

thobbs-mifcom commented 1 year ago

Though my investigations at home I am seeing the Release code running multiple main render methods in parallel despite the fact I implemented even tighter locking controls last night that should force the wait in the main thread. I believe this maybe happening because either because I have not use the static std::atomic for the thread count or more likely the compiler optimizations are running more of the code it thinks that it is okay to run in parallel. If static std::atomic does not work I can either:

thobbsinteractive commented 1 year ago

Adding the keys for each thead was not the solution. Neither was pragma optimize( "", off ). std::atomic was the solution. std::atomic<bool> m_isTaskRunning;