I have a problem that seems unpleasant to me. It seems I found a situation that is easy enough to work with, but it can lead to problems if: a) I run out of concentration during programming or b) someone else starts implementing my interfaces and does not know how to handle this situation.
Here is my main setup:
I have an abstract class that I use as a common interface for several data types. I adopted the paradigm of a non-virtual public interface (Sutter, 2001), as well as a fixed lock to ensure thread safety. An example interface class would look something like this (I did not mention locking and implementing the mutex, since I do not think they are relevant):
class Foo
{
public:
A( )
{
ScopedLock lock( mutex );
aImp( );
}
B( )
{
ScopedLock lock( mutex );
bImp( );
}
protected:
aImp( ) = 0;
bImp( ) = 0;
}
Then the user must implement aImp and bImp in which the problem occurs. If aImp performs some operation that uses bImp, it is extremely simple (and almost logical, in a sense) for this:
class Bar
{
protected:
aImp( )
{
...
B( );
...
}
bImp( )
{
...
}
}
. , - , ( B() bImp() ). , , , , .
- , ?
, . , , Windows EnterCriticalSection LeaveCriticalSection, . . boost:: mutex boost:: shared_mutex , , , (, -, ).