G
Guest
Found this piece of code in .Net SDK 2.0. Why do we need to use Interlocked
although AcquireWriterLock is supposed to serialize access and do the traick?
// C#
ReaderWriterLock rwLock = new ReaderWriterLock();
int counter = 0;
try
{
rwLock.AcquireWriterLock(1000);
try
{
Interlocked.Increment(ref counter);
}
finally
{
rwLock.ReleaseWriterLock();
}
}
catch (ApplicationException)
{
Console.WriteLine("Failed to get a Writer Lock");
}
Thank you for any tips.
although AcquireWriterLock is supposed to serialize access and do the traick?
// C#
ReaderWriterLock rwLock = new ReaderWriterLock();
int counter = 0;
try
{
rwLock.AcquireWriterLock(1000);
try
{
Interlocked.Increment(ref counter);
}
finally
{
rwLock.ReleaseWriterLock();
}
}
catch (ApplicationException)
{
Console.WriteLine("Failed to get a Writer Lock");
}
Thank you for any tips.