As far as I know, slim versions of synchronization primitives use spin waits before using resources of the kernel.
Is it true that ManualResetEventSlim
with spinCount
= 0 is the same as the usual ManualResetEvent
?
new ManualResetEventSlim(initialState: false, spinCount: 0);
If no, what is the essential difference between them? Do we have any benefits of using the slim-version without spin waits?
Looking at the source for Wait if you set the spin count to 0 then it's basically a
ManualResetEvent
but instead of using a kernel wait event it actually uses a monitor.The kernel wait event is only allocated if you explicitly ask for it, which save a transition into kernel mode to allocate it and set/reset it.
It's worth considering that although the
ManualResetEventSlim
won't spin if you set the spin count to 0 it's highly likely that the call toMonitor.Wait
will spin, so I suspect you're not actually avoiding a spin.