I’m new to threading and i’m wondering if i have good code.
Situation: 3 classes, Reader, Writer and Data. Writer write data to Data as fast as he can, Reader, reads in every second (if writer didn’t wrote new data he checks flag, if it’s true, there are new data to read, if not he can use old ones).
Please tell me is it a valid code for Data class:
class GameData
{
String GameData="";
bool newData = false;
public String ReadData()
{
newData = false;
return GameData;
}
public void WriteData(String d)
{
lock (this)
{
GameData = d;
newData = true;
}
}
}
Reader Write Lock Slim.Blocking Collection
A good starting points.