I have a series of objects that are all populated from a single thread. The bulk of the flow control is performed in said producer thread. In one or two places I read data out from other threads. Is there an existing diagnostic tool, attribute, etc. that can be used to assert that the creating thread is the only one calling some method so that I can catch programming errors during testing? I would like to avoid complicated class encapsulation to solve this.
public class Datastore
{
public Register( int id )
{
// must be called on producer thread - want to avoid locking 'just in case'. It is an invalid operation to be called from another thread.
}
public int GetTotal()
{
// can be called on any thread
}
// ... more class members, etc.
}
The above is for illustrative purposes only.
Is there an attribute or some kind of pattern that works like this:
public class Datastore
{
[AssertOnProducerThread]
public Register( int id )
{
}
public int GetTotal()
{
}
// ... more class members, etc.
}