lock inside lock

lock is a wrapper for Monitor.Enter and Monitor.Exit:

The lock keyword calls Enter at the start of the block and Exit at the end of the block. From the former’s documentation:

From the documentation for Monitor.Enter:

It is legal for the same thread to invoke Enter more than once without it blocking; however, an equal number of Exit calls must be invoked before other threads waiting on the object will unblock.

Because the calls to Enter and Exit are paired, your code pattern has well defined behaviour.

Note, however, that lock is not guaranteed to be an exception-less construct:

A ThreadInterruptedException is thrown if Interrupt interrupts a thread that is waiting to enter a lock statement.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)