Is it safe to signal and immediately close a ManualResetEvent?

前端 未结 4 1324
借酒劲吻你
借酒劲吻你 2021-01-17 13:34

I feel like I should know the answer to this, but I\'m going to ask anyway just in case I\'m making a potentially catastrophic mistake.

The following code executes a

4条回答
  •  Happy的楠姐
    2021-01-17 14:22

    Looks like a risky pattern to me, even if due to the [current] implementation, it is OK. you are trying to dispose a resource which may still be in use.

    It is like newing and constructing an object and deleting it blindly even before consumers of that object is done.

    Even otherwise there is a problem here. Program may exit, even before other threads ever got a chance to run. Thread pool threads are background threads.

    Given that you have to wait for other threads anyway, you might as well clean up afterwards.

提交回复
热议问题