I am writing a class (Foo) which, when instantiated, can be called from multiple threads.
Most methods of the Foo class can safely be called by multiple threads in parallel. One method of this class (logout()), requires that all other threads are done.
Before logout is called, the reference to foo is deleted from a thread-safe collection. So, no new thread will get a reference to the Foo object. However, there may be existing threads that are working on references to the Foo object that needs to be logged out.
I could have a counter that is incremented every time a thread enters the object, and decremented every time a thread leaves. In logout(), I could spin on while (counter != 0);
But I am thinking there is probably a better defined way/pattern out there to do this. Looking for the wisdom of the stackoverflow community here.