Monitor.Enter and Monitor.Exit in different threads

前端 未结 3 385
鱼传尺愫
鱼传尺愫 2020-12-11 16:21

Monitor.Enter and Monitor.Exit are designed to be called from the same thread. But, what if I need to release a lock in a different thread than acq

3条回答
  •  感情败类
    2020-12-11 17:01

    If you can use .NET 4.0 you can replace it with System.Threading.Semaphore which allows you to acquire permits in one thread and release them in another.

    The Semaphore class does not enforce thread identity on calls to WaitOne or Release.

提交回复
热议问题