I'm trying to prevent multiple calls to a DLL initialization function by using a std::lock object.
While using a program like this on a stand alone program works:
#include <mutex>
std::mutex mtx;
void main(){
mtx.lock();
(...)
mtx.unlock()
}
This exact same code cannot get past the mtx.lock() when called on a DLL.
BOOL APIENTRY DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
f_Init(VERSION_ID);
return TRUE;
}
//On another cpp file, a static library actually.
#include <mutex>
std::mutex mutex_state;
void f_Init(DWORD version){
//Acquire the state lock
mutex_state.lock(); //<-- Will NOT get past this line
(...)
mutex_state.unlock();
}
Why is it imposible to lock the mutex on this situation?
I'm currently using Microsoft Visual Studio 2013.