When exactly .NET Monitor goes to kernel-mode?

后端 未结 3 2208
傲寒
傲寒 2020-12-09 06:36

I would like to compile a list of all possible conditions making Monitor go to kernel-mode / use kernel sync object.

Sync block has a field to reference kernel objec

3条回答
  •  情深已故
    2020-12-09 06:56

    When the lock is heavily contended.

    If the lock is lightly contended, there is a quick CPU spinlock to wait for the lock to be free again, but if this doesn't wait long enough for the lock to be free, the thread will blocking wait on the mutex, which involves a kernel mode call to suspend the thread and other such management.

提交回复
热议问题