#185 Loki::Mutex has no effect on Windows

closed
nobody
None
5
2012-12-02
2012-11-30
Tja Poeh
No

Loki's locking paradigm expect locking and unlocking to take place by way of the oneliner
<code>
typename MyThreadingModel::Lock lock;
</code>
This requires locking to take place in the mutex's contructor, and unlocking in its destructor. On Windows though, Loki's default Mutex class makes use of a CRITICAL_SECTION, which is only created and destroyed in the contructor and destructor respectively. Neither EnterCriticalSection nor LeaveCriticalSection are called.
In my view, the constructor and destructor should be as follows:

Mutex() LOKI_THREADS_MUTEX_CTOR(mtx_)
{
LOKI_THREADS_MUTEX_INIT(&mtx_);
LOKI_THREADS_MUTEX_LOCK(&mtx_);
}
~Mutex()
{
LOKI_THREADS_MUTEX_UNLOCK(&mtx_);
LOKI_THREADS_MUTEX_DELETE(&mtx_);
}

Discussion

  • Tja Poeh
    Tja Poeh
    2012-12-02

    This problem is not a bug within the Loki library. It is something
    that is wrong with the compiler or other libraries you are using.

     
  • Tja Poeh
    Tja Poeh
    2012-12-02

    • status: open --> closed
     
  • Tja Poeh
    Tja Poeh
    2012-12-02

    Ah, dealing with race conditinos can make your mind fuzzy, apparently. Of course the locking is done by the Lock class of the threading policy.