title: How to restrict access to a class to only one thread
body: <p>I have a class called MathParser which has only one entry point which is &quot;Evaluate&quot; a static function which takes only one String input and outputs the evaluated result. The MathParser class has several booleans representing different functionality that can be switched on or off.</p>
  <p>In a single threaded application, The evaluate function will throw exceptions if things are not in desired order, and once it gets hold of the control flow, it will release it only when the processing is done ensuring complete safety from any kind of unexpected behavior.</p>
  <p>However, in a Multi-threaded Application, A different thread can also turn this switches on or off independently as they're all static and public variables, while the Evaluate function might still be processing the input. It can lead to all sorts of unexpected behaviors.</p>
  <p>So I wanted to know if a class and it's members can be made to be accessible only by one thread, either Main or a background, this way, no other thread will mess up things while processing is still midway.</p>