THREAD-SAFE INTERFACE

Minimizes locking overhead and ensures that intracomponent methods do not self-deadlock, by trying to reacquire a lock already held.


class LOCK
{
  public:
    virtual void acquire() = 0;
    virtual void release() = 0;
};
The abstract class LOCK must be subclassed by a concrete class implementing the acquire and release methods. A trivial example is a Null_Lock which provides empty implementations for both, and can be used when there is no need for locking.


template < class LOCK >
class Component
{
  public:
    // public interface methods which acquire/release the LOCK
    // and call internal methods
    void insert( const string & str );
   
  private:
    // internal methods performing the processing
    void insert_i( const string & str );

  private:
    mutable LOCK lock_;

};
Marco Corvi - Page hosted by geocities.com.