Replies: 1 comment
-
For your purposes, probably "a": the task you queue (despite the name, To fix these issues, you need to have a barrier that prevents the main thread from setting
.... multithreading is a non-trivial topic. As stated, that's probably not sufficiently specified advice. For instance, while |
Beta Was this translation helpful? Give feedback.
-
Hey guys,
I was hoping to show by the following xUnit test that
shouldStop
variable has to be synchronized (that one should uselock (obj) { ... }
). However, the test always passes (in both Debug and Release configurations; both were run in Visual Studio for Windows on an Intel x64 machine):Is the test passing because
a) it's wrong in some way
b) the hardware provides stronger memory guarantees (I vaguely remember I read about it some time ago).
c) there is some memory barrier that ruins my test
d) something else
e) my understanding of synchronization is wrong :)
?
Basically, my goal was to achieve what this sample https://stackoverflow.com/questions/133270/illustrating-usage-of-the-volatile-keyword-in-c-sharp/1284007#1284007 (not tested) achieves but
async
code (Task
s). To say it explicitly, I would like to show that there is a "missed write" (i.e. one thread writes a value something and a reading thread misses that change).Any feedback is welcome!
Thank you
PS: The goal of the unit test is just to persuade people that one should lock access to class fields when those class fields are accessed from mutliple threads as then no unwanted surprises arise.
Beta Was this translation helpful? Give feedback.
All reactions