We have some performance issues and are thinking about to take out some thread safe locks from some heavily used properties. More precisely only from the access modifier getter. The improvement would be that the setter access modifier is not "blocked" anymore if some other thread is making a get on the same property.
-> Of course it has to be ensured that if let's say for an integer type for example the bit value 11110011 which is 243, all bits are written once writing has started. It has to be ensured that never the write thread is unfinished and the get thread becomes some half written bits which results a wrong value. Is it like that?
If so, is that concept usable for all .net built in data types, also string?
See following code example which shows the concept:
// for properties used just the "Built-In Types"
// doc: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/built-in-types-table
private int _ActualValue = 0;
private readonly object _Lock_ActualValue = new object();
public int ActualValue
{
get
{
//lock(_Lock_ActualValue) <- remove lock for access modifier get ?
//{
return _ActualValue;
//}
}
set
{
lock (_Lock_ActualValue)
{
if((value != _ActualValue) && (value < 1000))
{
Log("_ActualValue", value.ToString());
_ActualValue = value;
}
}
}
}