use*_*375 5 .net c# readerwriterlockslim threadabortexception
我想检查以下代码是否能够抵抗 ThreadAbortException 并且不会导致孤儿锁。如果不是,那么避免孤儿锁的最佳模式是什么?
ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
public void DoStaff()
{
_lock.EnterWriteLock();
//Is this place where ThreadAbotException can corrupt my code, or is there JIT optimalization which prevent this from happening???
try
{
...
}
finally
{
_lock.ExitWriteLock();
}
}
Run Code Online (Sandbox Code Playgroud)
根据以下链接http://chabster.blogspot.cz/2013/07/a-story-of-orphaned-readerwriterlockslim.html,有(或至少有)可能的方法如何创建孤儿锁,但我正在运行示例编码了一段时间,没有任何运气。
我正在使用.NET 4.0
调试和发布中的行为有什么区别吗?
| 归档时间: |
|
| 查看次数: |
930 次 |
| 最近记录: |