Assume I have some array. All items are initially null
Thread1 writes to array. Thread2 blocks until all items in array are set (and then process).
I was doing it like that: I've created one another array with AutoResetEvent
. In Thread1 every time i update array item i call Set
to corresponding AutoResetEvent and in Thread2 I just WaitHandle.WaitAll(events);
But now I do think this is not efficient. I think that I should probably use one event. Because I can count how many items are updated yet, i can just raise event on last update.
This is simplified exmple, in real life things are a little bit harder, but probably you can suggest something better?
Also should I use Volatile.Read
in Thread1? (I have double-CPU machine).