[Mono-list] How to implement the monitor synchronization?
Rhys Weatherley
rweather@zip.com.au
Wed, 14 Nov 2001 09:54:59 +1000
Morten Sylvest Olsen wrote:
> But wait a second! What happens when control is transfered out of the
> basic block. Of course the compiler inserts call to monitor exit just
> before method return, but what about when exceptions are thrown. The CLI
> needs to release monitors when unwinding?
The CLR doesn't need to do anything special for monitors.
The C# compiler wraps "lock" blocks in a "try" statement
whose "finally" clause exits the monitor. Thus, both normal
and exceptional exits from the block will ensure that the
monitor is released.
Cheers,
Rhys.