www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Fixing race issues the right way

reply solidstate1991 <laszloszeremi outlook.com> writes:
My game engine is currently broken due to some race issue I don't 
really know how to resolve.

It seems that the compiler tries to skip instructions that are 
not locked with a `writeln()` or something similar. Usually I can 
safely remove the writeln after compiling it once with that way. 
However I've once ran into an issue when a previously working 
code just started to emit random junk data depending on CPU 
usage, and in that case the aforementioned workaround only 
partially worked (delaying crashes, etc).

I've heard something about Mutex, however I lack the experience 
with multithreading.
Apr 05 2020
next sibling parent reply Stefan Koch <uplink.coder gmail.com> writes:
On Sunday, 5 April 2020 at 22:24:27 UTC, solidstate1991 wrote:
 My game engine is currently broken due to some race issue I 
 don't really know how to resolve.

 It seems that the compiler tries to skip instructions that are 
 not locked with a `writeln()` or something similar. Usually I 
 can safely remove the writeln after compiling it once with that 
 way. However I've once ran into an issue when a previously 
 working code just started to emit random junk data depending on 
 CPU usage, and in that case the aforementioned workaround only 
 partially worked (delaying crashes, etc).

 I've heard something about Mutex, however I lack the experience 
 with multithreading.
Look at your program in a debugger and see if it does spawn threads. If it does find out where and why they are spawned.
Apr 05 2020
parent solidstate1991 <laszloszeremi outlook.com> writes:
On Sunday, 5 April 2020 at 22:33:50 UTC, Stefan Koch wrote:
 Look at your program in a debugger and see if it does spawn 
 threads.
 If it does find out where and why they are spawned.
Thanks for the answer, but it seems the issue was the lack of the ability of unittesting such a large package. So I broke out collections-d similarly to other projects.
Apr 20 2020
prev sibling parent Mathias LANG <geod24 gmail.com> writes:
On Sunday, 5 April 2020 at 22:24:27 UTC, solidstate1991 wrote:
 My game engine is currently broken due to some race issue I 
 don't really know how to resolve.

 It seems that the compiler tries to skip instructions that are 
 not locked with a `writeln()` or something similar. Usually I 
 can safely remove the writeln after compiling it once with that 
 way. However I've once ran into an issue when a previously 
 working code just started to emit random junk data depending on 
 CPU usage, and in that case the aforementioned workaround only 
 partially worked (delaying crashes, etc).

 I've heard something about Mutex, however I lack the experience 
 with multithreading.
Is there public code you can link to ? Look for any usage of `__gshared`. Are you using `shared` as well ? Turn on `-preview=nosharedaccess` to get better diagnostic. Are you using any `extern` code ? How do you communicate between threads ? Message passing, or simple shared memory ?
Apr 05 2020