G
Guest
I am a bit new to threading and something is not clear about
ReaderWriterlocks. I understood that it meant that any so called shared
resource wil be locked, thus in the following example from my application the
object dataargs would be locked (even if its local and it makes no sense to
lock it) but what about the objects used in this.GetData?
Some objects used in this method are shred between at least two threads are
they locked or do I have to move my lock in the method itself?
internal void ThreadedReadData (object dataArguments){
DataExchange dataArgs;
try
{
rwLock.AcquireWriterLock(RegistryValues.Keys.ThreadWriterLocksTimeout);
try
{
dataArgs = (DataExchange)dataArguments;
dataArgs.dataset = this.GetData(dataArgs.datasetName, dataArgs.sessID,
dataArgs.parameters, false);
dataArgs.dataRead = true;
dataArguments = dataArgs;
}
finally{rwLock.ReleaseWriterLock();}
}
catch (ApplicationException e)
{
dataArgs = (DataExchange)dataArguments;
eventWriter.Write("The connection ID was " + this.Guid + "\nThe session ID
was " + dataArgs.sessID , e, 1016);
}
}
ReaderWriterlocks. I understood that it meant that any so called shared
resource wil be locked, thus in the following example from my application the
object dataargs would be locked (even if its local and it makes no sense to
lock it) but what about the objects used in this.GetData?
Some objects used in this method are shred between at least two threads are
they locked or do I have to move my lock in the method itself?
internal void ThreadedReadData (object dataArguments){
DataExchange dataArgs;
try
{
rwLock.AcquireWriterLock(RegistryValues.Keys.ThreadWriterLocksTimeout);
try
{
dataArgs = (DataExchange)dataArguments;
dataArgs.dataset = this.GetData(dataArgs.datasetName, dataArgs.sessID,
dataArgs.parameters, false);
dataArgs.dataRead = true;
dataArguments = dataArgs;
}
finally{rwLock.ReleaseWriterLock();}
}
catch (ApplicationException e)
{
dataArgs = (DataExchange)dataArguments;
eventWriter.Write("The connection ID was " + this.Guid + "\nThe session ID
was " + dataArgs.sessID , e, 1016);
}
}