Код: Выделить всё
#include
#include
#include
#include
#include
std::future GetExceptionFromDeadThread()
{
return std::async(std::launch::async, []() {
try
{
throw std::invalid_argument("Some string long enough to allocate on the heap? ");
}
catch (std::invalid_argument e)
{
return e;
}
catch (...)
{
std::fprintf(stderr, "'std::rethrow_exception(future.get())' threw unexpected exception");
abort();
}
});
}
int main()
{
try
{
constexpr size_t numThreads(100);
std::vector futures;
while (true)
{
for (size_t i = 0; i < numThreads; ++i)
{
futures.push_back(GetExceptionFromDeadThread());
}
while (!futures.empty())
{
auto& future(futures.back());
future.wait();
try
{
throw future.get();
}
catch (std::invalid_argument&)
{
std::fputs(".", stdout);
}
catch (...)
{
std::fprintf(stderr, "'std::rethrow_exception(future.get())' threw unexpected exception");
abort();
}
futures.pop_back();
}
}
}
catch (...)
{
std::fprintf(stderr, "Caught unexpected exception");
abort();
}
}
rtlvalidateHeap (0000021a37bb0000, 00007fffda43a2f0 ) < /p>
< /blockquote>
Код: Выделить всё
> ntdll.dll!RtlpBreakPointHeap() Unknown
ntdll.dll!RtlpValidateHeapEntry() Unknown
ntdll.dll!RtlValidateHeap() Unknown
KernelBase.dll!HeapValidate() Unknown
ucrtbased.dll!_CrtIsValidHeapPointer(const void * block) Line 1407 C++
ucrtbased.dll!free_dbg_nolock(void * const block, const int block_use) Line 904 C++
ucrtbased.dll!_free_dbg(void * block, int block_use) Line 1030 C++
ucrtbased.dll!free(void * block) Line 32 C++
vcruntime140d.dll!__std_exception_destroy(__std_exception_data * data) Line 46 C++
exception_ptr_test.exe!std::exception::~exception() Line 91 C++
exception_ptr_test.exe!std::logic_error::~logic_error() C++
exception_ptr_test.exe!std::invalid_argument::~invalid_argument() C++
exception_ptr_test.exe!std::_Packaged_state::_Call_immediate() Line 494 C++
exception_ptr_test.exe!std::_Task_async_state::{ctor}::__l2::::operator()() Line 664 C++
exception_ptr_test.exe!std::invoke(std::_Task_async_state::{ctor}::__l2:: & _Obj) Line 1695 C++
exception_ptr_test.exe!std::_Func_impl_no_alloc::_Do_call() Line 874 C++
exception_ptr_test.exe!std::_Func_class::operator()() Line 920 C++
exception_ptr_test.exe!Concurrency::details::_MakeVoidToUnitFunc::__l2::::operator()() Line 2363 C++
exception_ptr_test.exe!std::invoke(Concurrency::details::_MakeVoidToUnitFunc::__l2:: & _Obj) Line 1696 C++
exception_ptr_test.exe!std::_Func_impl_no_alloc::_Do_call() Line 878 C++
exception_ptr_test.exe!std::_Func_class::operator()() Line 921 C++
exception_ptr_test.exe!Concurrency::task::_InitialTaskHandle::_LogWorkItemAndInvokeUserLambda(std::function _func) Line 3528 C++
exception_ptr_test.exe!Concurrency::task::_InitialTaskHandle::_Init(Concurrency::details::_TypeSelectorNoAsync __formal) Line 3548 C++
exception_ptr_test.exe!Concurrency::task::_InitialTaskHandle::_Perform() Line 3533 C++
exception_ptr_test.exe!Concurrency::details::_PPLTaskHandle::invoke() Line 1475 C++
exception_ptr_test.exe!Concurrency::details::_TaskProcHandle::_RunChoreBridge(void * _Parameter) Line 171 C++
exception_ptr_test.exe!Concurrency::details::_DefaultPPLTaskScheduler::_PPLTaskChore::_Callback(void * _Args) Line 57 C++
msvcp140d.dll!Concurrency::details::`anonymous namespace'::_Task_scheduler_callback(_TP_CALLBACK_INSTANCE * _Pci, void * _Args, _TP_WORK * __formal) Line 134 C++
ntdll.dll!TppWorkpExecuteCallback() Unknown
ntdll.dll!TppWorkerThread() Unknown
kernel32.dll!BaseThreadInitThunk() Unknown
ntdll.dll!RtlUserThreadStart() Unknown
Кроме того, изменение return e , чтобы вернуть std :: Invalid_argument (e) заставляет сбой исчезнуть.
Подробнее здесь: https://stackoverflow.com/questions/794 ... c-crashing
Мобильная версия