SCM

[#1010998] Consider using Interlocked.Increment / Decrement operations for referrence counting

View Trackers | Bugs | Download .csv | Monitor

Date:
2011-02-22 14:07
Priority:
3
State:
Open
Submitted by:
Alex A Ermoshenko (erax)
Assigned to:
Nobody (None)
Npgsql Version:
None
Category:
Group:
Resolution:
None
Summary:
Consider using Interlocked.Increment / Decrement operations for referrence counting

Detailed description
Example for NotificationThread:
1) change type of field _notificationThreadStopCount to Int32
2) use this code

private void StopNotificationThread()
{
// first check to see if an exception has
// been thrown by the notification thread.
if (_notificationException != null)
throw _notificationException;

//_notificationThreadStopCount++;
if (Interlocked.Increment(ref _notificationThreadStopCount) == 1) // If this call was the first to increment.
{
_notificationAutoResetEvent.WaitOne();
}
}
private void ResumeNotificationThread()
{
//_notificationThreadStopCount--;
if (Interlocked.Decrement(ref _notificationThreadStopCount) == 0)
{
// Release the synchronization handle.
_notificationAutoResetEvent.Set();
}
}

Followup

No Followups Have Been Posted

Attached Files:

Changes:

No Changes Have Been Made to This Item

Powered By FusionForge