Assume I have shared double variable. Thread A updates it several thousands times per second. In another thread B I want to be notified somehow about “update” every time this happens.
I was tried to avoid notifications completely and just use while(true) loop but this introduced significant slowdowns into my program lock-free calc: how to sum N double numbers that are changing by other threads? probably because of that “Meanwhile you keep on loading that same array from memory over and over which is not really good for performance since memory bandwith is limited.”
I’ve also tried using Monitor class but it was also pretty slow and I’ve seen up to 1-2 ms delays when Monitor.TryEnter return false.
I now think that I need to do notifications using lock-free technique, probably using SpinLock or something else?
Use wait handle to notify between threads