我收到了崩溃转储。其中一些具有以下堆栈跟踪:
msvcr120.dll!Concurrency::details::_RegisterConcRTEventTracing() Line 240 C++
msvcr120.dll!Concurrency::details::SchedulerBase::CreateWithoutInitializing(const Concurrency::SchedulerPolicy & policy) Line 283 C++
msvcr120.dll!Concurrency::details::SchedulerBase::CreateContextFromDefaultScheduler() Line 571 C++
msvcr120.dll!Concurrency::details::SchedulerBase::CurrentContext() Line 404 C++
msvcr120.dll!Concurrency::critical_section::lock() Line 1031 C++
msvcp120.dll!mtx_do_lock(_Mtx_internal_imp_t * * mtx, const xtime * target) Line 67 C++
app.exe!vmsRaisesVaEvents::SubscribeToVaEvents(vmsConsumesVaEvents * pSubscriber) Line 14 C++
app.exe!vmsSiHtml5UiApp::MakeSureSplashCreated(CSiHtml5AppStartingSplash::SplashScreenMode ssmRequired) Line 458 C++
app.exe!vmsSiHtml5UiApp::PerformWbaPreInitializationIfRequired() Line 63 C++
app.exe!vmsSiHtml5UiApp::RunAsNonUiAuxiliaryProcess() Line 140 C++
app.exe!vmsSiApp::Run() Line 106 C++
app.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 23 C++
[External Code]
[Frames may be missing, no binary loaded for ntdll.dll]
ntdll.dll!0000000076ed3021() Unknown
我的应用程序刚刚启动并初始化。它有我的应用程序的一个线程(主线程)和其他5个由我不知道的东西创建的线程。但它们不属于我的代码。
在MakeSureSplashCreated函数中,我创建了对象。
m_spSplashMgr = std::make_shared <vmsSiHtml5AppStartingSplashMgr>
订阅其活动:
m_spSplashMgr->SubscribeToVaEvents (this);
Object派生自vmsRaisesVaEvents类以提供此功能。它的代码:
class vmsRaisesVaEvents
{
public:
vmsRaisesVaEvents () :
m_rasingEvents (0) {}
virtual ~vmsRaisesVaEvents () {}
void SubscribeToVaEvents (vmsConsumesVaEvents *pSubscriber)
{
std::unique_lock <std::mutex> lock (ms_events);
wait_for_events_raising_complete (lock);
assert (std::find (m_vSubscribers.begin (), m_vSubscribers.end (), pSubscriber) == m_vSubscribers.end ());
m_vSubscribers.push_back (pSubscriber);
}
void UnsubscribeFromVaEvents (vmsConsumesVaEvents *pSubscriber)
{
std::unique_lock <std::mutex> lock (ms_events);
wait_for_events_raising_complete (lock);
auto it = std::find (m_vSubscribers.begin (), m_vSubscribers.end (), pSubscriber);
assert (it != m_vSubscribers.end ());
if (it != m_vSubscribers.end ())
m_vSubscribers.erase (it);
}
private:
static std::mutex ms_events;
unsigned m_rasingEvents;
protected:
std::vector <vmsConsumesVaEvents*> m_vSubscribers;
protected:
void wait_for_events_raising_complete (std::unique_lock <std::mutex> &lock)
{
for (;;)
{
if (!m_rasingEvents)
return;
lock.unlock ();
Sleep (0);
lock.lock ();
}
}
void begin_raise_events ()
{
std::unique_lock <std::mutex> lock (ms_events);
m_rasingEvents++;
}
void end_raise_events ()
{
std::unique_lock <std::mutex> lock (ms_events);
assert (m_rasingEvents);
m_rasingEvents--;
}
protected:
void RaiseEvent (unsigned nEvent, ...)
{
va_list args;
va_start (args, nEvent);
begin_raise_events ();
for (auto it = m_vSubscribers.begin (); it != m_vSubscribers.end (); ++it)
(*it)->onVaEvent (this, nEvent, args);
end_raise_events ();
va_end (args);
}
};
__declspec(selectany) std::mutex vmsRaisesVaEvents::ms_events;
我在这行的vmsRaisesVaEvents :: SubscribeToVaEvents中崩溃了:
std::unique_lock <std::mutex> lock (ms_events);
为什么这样?唯一可疑的是:
__declspec(selectany) std::mutex vmsRaisesVaEvents::ms_events;
除此之外,所有对象必须处于良好状态(存在,未损坏等)。