locked
Combining many PPL tasks using && causes stack overflow. RRS feed

  • Question

  • The title pretty much says it all. Here's an example from our code base:

    	auto task = (createPSTask && createVSTask);
    	for (std::set<Texture*>::iterator i(T::GetTextures().begin()); i != T::GetTextures().end(); ++i)
    		task = task && (*i)->Load();
    	task.then([this] () {
    		readyToRender = true;
    	});
    

    I think we've found a workaround, simply by not having yet seen a stack overflow exception after a few runs, but of course I can't guarantee that this actually is a working fix:

    	auto task = (createPSTask && createVSTask);
    	for (std::set<Texture*>::iterator i(T::GetTextures().begin()); i != T::GetTextures().end(); ++i)
    		task = task.then([=] { return (*i)->Load(); });
    	task.then([this] () {
    		readyToRender = true;
    

    I don't know if this is acceptable behavior that users are expected to work around - similar to knowing when to use a recursive function and when not to, but it would be nice if the PPL runtime was smart enough to figure out when it should do things to avoid stack overflow. Is this a bug, or an undocumented feature?


    Software Engineer, Brainium Studios LLC

    Friday, May 11, 2012 6:24 PM

Answers

  • Brent,

    Thanks for reporting this. We have found and fixed some issues around recursion since the Consumer Preview, but this is not one of them. In general if you have a list of tasks you want to chain together, && is not the most effecient operation. it is perfect for pairs but if you &&= 1000 or so tasks, it could create a bit of overhead. May I suggest something like this?

    	std::vector<task<void>> allTasks;
    	allTasks.push_back(createPSTask && createVSTask); // ok to do this since createPSTask && createVSTask returns task<void>
    	for (std::set<Texture*>::iterator i(T::GetTextures().begin()); i != T::GetTextures().end(); ++i)
    		allTasks.push_back((*i)->Load());
    	when_all(allTasks.begin(), allTasks.end()).then([this] () {
    		readyToRender = true;
    	});

    Friday, May 11, 2012 8:25 PM

All replies

  • Brent,

    Thanks for reporting this. We have found and fixed some issues around recursion since the Consumer Preview, but this is not one of them. In general if you have a list of tasks you want to chain together, && is not the most effecient operation. it is perfect for pairs but if you &&= 1000 or so tasks, it could create a bit of overhead. May I suggest something like this?

    	std::vector<task<void>> allTasks;
    	allTasks.push_back(createPSTask && createVSTask); // ok to do this since createPSTask && createVSTask returns task<void>
    	for (std::set<Texture*>::iterator i(T::GetTextures().begin()); i != T::GetTextures().end(); ++i)
    		allTasks.push_back((*i)->Load());
    	when_all(allTasks.begin(), allTasks.end()).then([this] () {
    		readyToRender = true;
    	});

    Friday, May 11, 2012 8:25 PM
  • Unfortunately, this is still resulting in a stack overflow. In our case we're creating about 170 tasks.

    This is the stack trace with most of the repetitions removed from its middle. The beginning and end are still intact.

    ntdll.dll!_NtRaiseException@12() Unknown ntdll.dll!_KiUserExceptionDispatcher@8() Unknown rpcrt4.dll!NdrLoadNdrOleExtension(void) Unknown rpcrt4.dll!_NdrStubCall2@16() Unknown combase.dll!_CStdStubBuffer_Invoke@12() Unknown combase.dll!SyncStubInvoke(struct tagRPCOLEMESSAGE *,struct _GUID const &,class CIDObject *,void *,struct IRpcChannelBuffer *,struct IRpcStubBuffer *,unsigned long *) Unknown combase.dll!CCtxComChnl::ContextInvoke(struct tagRPCOLEMESSAGE *,struct IRpcStubBuffer *,struct tagIPIDEntry *,unsigned long *) Unknown combase.dll!ComInvokeWithLockAndIPID(class CMessageCall *,struct tagIPIDEntry *) Unknown combase.dll!ComInvoke(class CMessageCall *) Unknown combase.dll!ThreadDispatch(class CMessageCall *) Unknown combase.dll!CComApartment::ASTAHandleMessage(class IMessageParam *) Unknown combase.dll!ASTAWaitContext::HandlePriorityEvents(void) Unknown combase.dll!ASTAWaitContext::Wait(unsigned int,void * const *,unsigned long,struct ASTAWaitContext::ProcessEventsMsgWaitParams *,unsigned long *) Unknown combase.dll!ASTAWait(enum BlockingReason,unsigned int,void * const *,unsigned long,unsigned long,unsigned long,unsigned int *,unsigned long *) Unknown combase.dll!ASTAThreadWaitForCall(class CMessageCall *) Unknown combase.dll!ASTAThreadDispatchCrossApartmentCall(class OXIDEntry *,class CMessageCall *) Unknown combase.dll!CRpcChannelBuffer::SendReceive2(struct tagRPCOLEMESSAGE *,unsigned long *) Unknown combase.dll!CCtxComChnl::SendReceive(struct tagRPCOLEMESSAGE *,unsigned long *) Unknown combase.dll!NdrExtpProxySendReceive(void *,struct _MIDL_STUB_MESSAGE *) Unknown rpcrt4.dll!@NdrpProxySendReceive@4() Unknown rpcrt4.dll!_NdrClientCall2() Unknown combase.dll!_ObjectStublessClient@8() Unknown combase.dll!_ObjectStubless@0() Unknown combase.dll!CObjectContext::InternalContextCallback(long (*)(void *),void *,struct _GUID const &,int,struct IUnknown *) Unknown combase.dll!CObjectContext::ContextCallback(long (*)(struct tagComCallData *),struct tagComCallData *,struct _GUID const &,int,struct IUnknown *) Unknown > Jumbline2Win.exe!Concurrency::details::_ContextCallback::_CallInContext(std::function<void __cdecl(void)> _Func) Line 640 C++ Jumbline2Win.exe!Concurrency::details::_MarshalHelper<Windows::Graphics::Imaging::BitmapFrame>::_Perform(Windows::Graphics::Imaging::BitmapFrame ^ _ObjInCtx, const Concurrency::details::_ContextCallback & _Ctx) Line 806 C++ Jumbline2Win.exe!Concurrency::details::_Marshal<Windows::Graphics::Imaging::BitmapFrame>(Windows::Graphics::Imaging::BitmapFrame ^ _ObjInCtx, const Concurrency::details::_ContextCallback & _Ctx) Line 843 C++ Jumbline2Win.exe!Concurrency::details::_InContext<Windows::Graphics::Imaging::BitmapFrame ^>::_Get(Windows::Graphics::Imaging::BitmapFrame ^ _ObjInCtx, const Concurrency::details::_ContextCallback & _Ctx) Line 869 C++ Jumbline2Win.exe!Concurrency::details::_ResultContext<Windows::Graphics::Imaging::BitmapFrame ^>::_GetValue(Windows::Graphics::Imaging::BitmapFrame ^ _ObjInCtx, const Concurrency::details::_ContextCallback & _Ctx, bool __formal) Line 878 C++ Jumbline2Win.exe!Concurrency::details::_Task_impl<Windows::Graphics::Imaging::BitmapFrame ^>::_GetResult() Line 2190 C++ Jumbline2Win.exe!Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>::_Continue(std::integral_constant<bool,0> __formal, Concurrency::details::_TypeSelectorAsyncOperationOrTask __formal) Line 3176 C++ Jumbline2Win.exe!Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>::_Perform() Line 3148 C++ Jumbline2Win.exe!Concurrency::details::_PPLTaskHandle<Windows::Graphics::Imaging::PixelDataProvider ^,Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>,Concurrency::details::_ContinuationTaskHandleBase>::operator()() Line 1131 C++ Jumbline2Win.exe!Concurrency::details::_UnrealizedChore::_InvokeBridge<Concurrency::details::_PPLTaskHandle<Windows::Graphics::Imaging::PixelDataProvider ^,Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>,Concurrency::details::_ContinuationTaskHandleBase> >(Concurrency::details::_PPLTaskHandle<Windows::Graphics::Imaging::PixelDataProvider ^,Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>,Concurrency::details::_ContinuationTaskHandleBase> * _PChore) Line 4453 C++ msvcr110d.dll!Concurrency::details::_TaskCollection::_RunAndWait(Concurrency::details::_UnrealizedChore * pChore) Line 1599 C++ Jumbline2Win.exe!Concurrency::details::_AsyncTaskCollection::_RunAndWait(Concurrency::details::_UnrealizedChore * _PChore) Line 5431 C++ Jumbline2Win.exe!Concurrency::details::_Task_impl_base::_ScheduleTask(Concurrency::details::_UnrealizedChore * _PTaskHandle, bool _IsInlineExecution) Line 1501 C++ Jumbline2Win.exe!<lambda_d7417fe17f84cb0340a874130b40b35d>::operator()() Line 1598 C++ Jumbline2Win.exe!std::_Callable_obj<<lambda_d7417fe17f84cb0340a874130b40b35d>,0>::_ApplyX<void>() Line 420 C++ Jumbline2Win.exe!std::_Func_impl<std::_Callable_obj<<lambda_d7417fe17f84cb0340a874130b40b35d>,0>,std::allocator<std::_Func_class<void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil> >,void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil>::_Do_call() Line 222 C++ Jumbline2Win.exe!std::_Func_class<void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil>::operator()() Line 495 C++ Jumbline2Win.exe!Concurrency::details::_ContextCallback::_Bridge(tagComCallData * _PParam) Line 681 C++ combase.dll!CRemoteUnknown::DoCallback(struct tagXAptCallback *) Unknown rpcrt4.dll!_Invoke@12() Unknown rpcrt4.dll!_NdrStubCall2@16() Unknown combase.dll!_CStdStubBuffer_Invoke@12() Unknown combase.dll!SyncStubInvoke(struct tagRPCOLEMESSAGE *,struct _GUID const &,class CIDObject *,void *,struct IRpcChannelBuffer *,struct IRpcStubBuffer *,unsigned long *) Unknown combase.dll!CCtxComChnl::ContextInvoke(struct tagRPCOLEMESSAGE *,struct IRpcStubBuffer *,struct tagIPIDEntry *,unsigned long *) Unknown combase.dll!ComInvokeWithLockAndIPID(class CMessageCall *,struct tagIPIDEntry *) Unknown combase.dll!ComInvoke(class CMessageCall *) Unknown combase.dll!ThreadDispatch(class CMessageCall *) Unknown combase.dll!CComApartment::ASTAHandleMessage(class IMessageParam *) Unknown combase.dll!ASTAWaitContext::HandlePriorityEvents(void) Unknown combase.dll!ASTAWaitContext::Wait(unsigned int,void * const *,unsigned long,struct ASTAWaitContext::ProcessEventsMsgWaitParams *,unsigned long *) Unknown combase.dll!ASTAWait(enum BlockingReason,unsigned int,void * const *,unsigned long,unsigned long,unsigned long,unsigned int *,unsigned long *) Unknown combase.dll!ASTAThreadWaitForCall(class CMessageCall *) Unknown combase.dll!ASTAThreadDispatchCrossApartmentCall(class OXIDEntry *,class CMessageCall *) Unknown combase.dll!CRpcChannelBuffer::SendReceive2(struct tagRPCOLEMESSAGE *,unsigned long *) Unknown combase.dll!CCtxComChnl::SendReceive(struct tagRPCOLEMESSAGE *,unsigned long *) Unknown combase.dll!NdrExtpProxySendReceive(void *,struct _MIDL_STUB_MESSAGE *) Unknown rpcrt4.dll!@NdrpProxySendReceive@4() Unknown rpcrt4.dll!_NdrClientCall2() Unknown combase.dll!_ObjectStublessClient@8() Unknown combase.dll!_ObjectStubless@0() Unknown combase.dll!CObjectContext::InternalContextCallback(long (*)(void *),void *,struct _GUID const &,int,struct IUnknown *) Unknown combase.dll!CObjectContext::ContextCallback(long (*)(struct tagComCallData *),struct tagComCallData *,struct _GUID const &,int,struct IUnknown *) Unknown Jumbline2Win.exe!Concurrency::details::_ContextCallback::_CallInContext(std::function<void __cdecl(void)> _Func) Line 640 C++ Jumbline2Win.exe!Concurrency::details::_MarshalHelper<Windows::Graphics::Imaging::BitmapFrame>::_Perform(Windows::Graphics::Imaging::BitmapFrame ^ _ObjInCtx, const Concurrency::details::_ContextCallback & _Ctx) Line 806 C++ Jumbline2Win.exe!Concurrency::details::_Marshal<Windows::Graphics::Imaging::BitmapFrame>(Windows::Graphics::Imaging::BitmapFrame ^ _ObjInCtx, const Concurrency::details::_ContextCallback & _Ctx) Line 843 C++ Jumbline2Win.exe!Concurrency::details::_InContext<Windows::Graphics::Imaging::BitmapFrame ^>::_Get(Windows::Graphics::Imaging::BitmapFrame ^ _ObjInCtx, const Concurrency::details::_ContextCallback & _Ctx) Line 869 C++ Jumbline2Win.exe!Concurrency::details::_ResultContext<Windows::Graphics::Imaging::BitmapFrame ^>::_GetValue(Windows::Graphics::Imaging::BitmapFrame ^ _ObjInCtx, const Concurrency::details::_ContextCallback & _Ctx, bool __formal) Line 878 C++ Jumbline2Win.exe!Concurrency::details::_Task_impl<Windows::Graphics::Imaging::BitmapFrame ^>::_GetResult() Line 2190 C++ Jumbline2Win.exe!Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>::_Continue(std::integral_constant<bool,0> __formal, Concurrency::details::_TypeSelectorAsyncOperationOrTask __formal) Line 3176 C++ Jumbline2Win.exe!Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>::_Perform() Line 3148 C++ Jumbline2Win.exe!Concurrency::details::_PPLTaskHandle<Windows::Graphics::Imaging::PixelDataProvider ^,Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>,Concurrency::details::_ContinuationTaskHandleBase>::operator()() Line 1131 C++ Jumbline2Win.exe!Concurrency::details::_UnrealizedChore::_InvokeBridge<Concurrency::details::_PPLTaskHandle<Windows::Graphics::Imaging::PixelDataProvider ^,Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>,Concurrency::details::_ContinuationTaskHandleBase> >(Concurrency::details::_PPLTaskHandle<Windows::Graphics::Imaging::PixelDataProvider ^,Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>,Concurrency::details::_ContinuationTaskHandleBase> * _PChore) Line 4453 C++ msvcr110d.dll!Concurrency::details::_TaskCollection::_RunAndWait(Concurrency::details::_UnrealizedChore * pChore) Line 1599 C++ Jumbline2Win.exe!Concurrency::details::_AsyncTaskCollection::_RunAndWait(Concurrency::details::_UnrealizedChore * _PChore) Line 5431 C++ Jumbline2Win.exe!Concurrency::details::_Task_impl_base::_ScheduleTask(Concurrency::details::_UnrealizedChore * _PTaskHandle, bool _IsInlineExecution) Line 1501 C++ Jumbline2Win.exe!<lambda_d7417fe17f84cb0340a874130b40b35d>::operator()() Line 1598 C++ Jumbline2Win.exe!std::_Callable_obj<<lambda_d7417fe17f84cb0340a874130b40b35d>,0>::_ApplyX<void>() Line 420 C++ Jumbline2Win.exe!std::_Func_impl<std::_Callable_obj<<lambda_d7417fe17f84cb0340a874130b40b35d>,0>,std::allocator<std::_Func_class<void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil> >,void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil>::_Do_call() Line 222 C++ Jumbline2Win.exe!std::_Func_class<void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil>::operator()() Line 495 C++ Jumbline2Win.exe!Concurrency::details::_ContextCallback::_Bridge(tagComCallData * _PParam) Line 681 C++ combase.dll!CRemoteUnknown::DoCallback(struct tagXAptCallback *) Unknown rpcrt4.dll!_Invoke@12() Unknown rpcrt4.dll!_NdrStubCall2@16() Unknown combase.dll!_CStdStubBuffer_Invoke@12() Unknown combase.dll!SyncStubInvoke(struct tagRPCOLEMESSAGE *,struct _GUID const &,class CIDObject *,void *,struct IRpcChannelBuffer *,struct IRpcStubBuffer *,unsigned long *) Unknown combase.dll!CCtxComChnl::ContextInvoke(struct tagRPCOLEMESSAGE *,struct IRpcStubBuffer *,struct tagIPIDEntry *,unsigned long *) Unknown combase.dll!ComInvokeWithLockAndIPID(class CMessageCall *,struct tagIPIDEntry *) Unknown combase.dll!ComInvoke(class CMessageCall *) Unknown combase.dll!ThreadDispatch(class CMessageCall *) Unknown combase.dll!CComApartment::ASTAHandleMessage(class IMessageParam *) Unknown combase.dll!ASTAWaitContext::HandlePriorityEvents(void) Unknown combase.dll!ASTAWaitContext::Wait(unsigned int,void * const *,unsigned long,struct ASTAWaitContext::ProcessEventsMsgWaitParams *,unsigned long *) Unknown combase.dll!ASTAWait(enum BlockingReason,unsigned int,void * const *,unsigned long,unsigned long,unsigned long,unsigned int *,unsigned long *) Unknown combase.dll!ASTAThreadWaitForCall(class CMessageCall *) Unknown combase.dll!ASTAThreadDispatchCrossApartmentCall(class OXIDEntry *,class CMessageCall *) Unknown combase.dll!CRpcChannelBuffer::SendReceive2(struct tagRPCOLEMESSAGE *,unsigned long *) Unknown combase.dll!CCtxComChnl::SendReceive(struct tagRPCOLEMESSAGE *,unsigned long *) Unknown combase.dll!NdrExtpProxySendReceive(void *,struct _MIDL_STUB_MESSAGE *) Unknown rpcrt4.dll!@NdrpProxySendReceive@4() Unknown rpcrt4.dll!_NdrClientCall2() Unknown combase.dll!_ObjectStublessClient@8() Unknown combase.dll!_ObjectStubless@0() Unknown combase.dll!CObjectContext::InternalContextCallback(long (*)(void *),void *,struct _GUID const &,int,struct IUnknown *) Unknown combase.dll!CObjectContext::ContextCallback(long (*)(struct tagComCallData *),struct tagComCallData *,struct _GUID const &,int,struct IUnknown *) Unknown Jumbline2Win.exe!Concurrency::details::_ContextCallback::_CallInContext(std::function<void __cdecl(void)> _Func) Line 640 C++ Jumbline2Win.exe!Concurrency::details::_MarshalHelper<Windows::Graphics::Imaging::BitmapFrame>::_Perform(Windows::Graphics::Imaging::BitmapFrame ^ _ObjInCtx, const Concurrency::details::_ContextCallback & _Ctx) Line 806 C++ Jumbline2Win.exe!Concurrency::details::_Marshal<Windows::Graphics::Imaging::BitmapFrame>(Windows::Graphics::Imaging::BitmapFrame ^ _ObjInCtx, const Concurrency::details::_ContextCallback & _Ctx) Line 843 C++ Jumbline2Win.exe!Concurrency::details::_InContext<Windows::Graphics::Imaging::BitmapFrame ^>::_Get(Windows::Graphics::Imaging::BitmapFrame ^ _ObjInCtx, const Concurrency::details::_ContextCallback & _Ctx) Line 869 C++ Jumbline2Win.exe!Concurrency::details::_ResultContext<Windows::Graphics::Imaging::BitmapFrame ^>::_GetValue(Windows::Graphics::Imaging::BitmapFrame ^ _ObjInCtx, const Concurrency::details::_ContextCallback & _Ctx, bool __formal) Line 878 C++ Jumbline2Win.exe!Concurrency::details::_Task_impl<Windows::Graphics::Imaging::BitmapFrame ^>::_GetResult() Line 2190 C++ Jumbline2Win.exe!Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>::_Continue(std::integral_constant<bool,0> __formal, Concurrency::details::_TypeSelectorAsyncOperationOrTask __formal) Line 3176 C++ Jumbline2Win.exe!Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>::_Perform() Line 3148 C++ Jumbline2Win.exe!Concurrency::details::_PPLTaskHandle<Windows::Graphics::Imaging::PixelDataProvider ^,Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>,Concurrency::details::_ContinuationTaskHandleBase>::operator()() Line 1131 C++ Jumbline2Win.exe!Concurrency::details::_UnrealizedChore::_InvokeBridge<Concurrency::details::_PPLTaskHandle<Windows::Graphics::Imaging::PixelDataProvider ^,Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>,Concurrency::details::_ContinuationTaskHandleBase> >(Concurrency::details::_PPLTaskHandle<Windows::Graphics::Imaging::PixelDataProvider ^,Concurrency::task<Windows::Graphics::Imaging::BitmapFrame ^>::_ContinuationTaskHandle<Windows::Graphics::Imaging::BitmapFrame ^,Windows::Graphics::Imaging::PixelDataProvider ^,<lambda_625dfb21478c5f591841320f5bd127eb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>,Concurrency::details::_ContinuationTaskHandleBase> * _PChore) Line 4453 C++ msvcr110d.dll!Concurrency::details::_TaskCollection::_RunAndWait(Concurrency::details::_UnrealizedChore * pChore) Line 1599 C++ Jumbline2Win.exe!Concurrency::details::_AsyncTaskCollection::_RunAndWait(Concurrency::details::_UnrealizedChore * _PChore) Line 5431 C++ Jumbline2Win.exe!Concurrency::details::_Task_impl_base::_ScheduleTask(Concurrency::details::_UnrealizedChore * _PTaskHandle, bool _IsInlineExecution) Line 1501 C++ Jumbline2Win.exe!<lambda_d7417fe17f84cb0340a874130b40b35d>::operator()() Line 1598 C++ Jumbline2Win.exe!std::_Callable_obj<<lambda_d7417fe17f84cb0340a874130b40b35d>,0>::_ApplyX<void>() Line 420 C++ Jumbline2Win.exe!std::_Func_impl<std::_Callable_obj<<lambda_d7417fe17f84cb0340a874130b40b35d>,0>,std::allocator<std::_Func_class<void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil> >,void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil>::_Do_call() Line 222 C++ Jumbline2Win.exe!std::_Func_class<void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil>::operator()() Line 495 C++ Jumbline2Win.exe!Concurrency::details::_ContextCallback::_Bridge(tagComCallData * _PParam) Line 681 C++ combase.dll!CRemoteUnknown::DoCallback(struct tagXAptCallback *) Unknown rpcrt4.dll!_Invoke@12() Unknown

      rpcrt4.dll!_NdrStubCall2@16() Unknown
      combase.dll!_CStdStubBuffer_Invoke@12() Unknown
      combase.dll!SyncStubInvoke(struct tagRPCOLEMESSAGE *,struct _GUID const &,class CIDObject *,void *,struct IRpcChannelBuffer *,struct IRpcStubBuffer *,unsigned long *) Unknown
      combase.dll!CCtxComChnl::ContextInvoke(struct tagRPCOLEMESSAGE *,struct IRpcStubBuffer *,struct tagIPIDEntry *,unsigned long *) Unknown
      combase.dll!ComInvokeWithLockAndIPID(class CMessageCall *,struct tagIPIDEntry *) Unknown
      combase.dll!ComInvoke(class CMessageCall *) Unknown
      combase.dll!ThreadDispatch(class CMessageCall *) Unknown
      combase.dll!CComApartment::ASTAHandleMessage(class IMessageParam *) Unknown
      combase.dll!ASTAWaitContext::HandlePriorityEvents(void) Unknown
      combase.dll!ASTAWaitContext::Wait(unsigned int,void * const *,unsigned long,struct ASTAWaitContext::ProcessEventsMsgWaitParams *,unsigned long *) Unknown
      combase.dll!_CoMsgWaitInProcessEvents@24() Unknown
      Windows.UI.dll!Windows::UI::Core::CDispatcher::ProcessEvents(enum Windows::UI::Core::CoreProcessEventsOption) Unknown
      Windows.UI.Xaml.dll!CJupiterWindow::RunCoreWindowMessageLoop() Line 348 C++
      Windows.UI.Xaml.dll!CJupiterControl::RunMessageLoop() Line 697 C++
      Windows.UI.Xaml.dll!DirectUI::DXamlCore::RunMessageLoop() Line 2134 C++
      Windows.UI.Xaml.dll!DirectUI::FrameworkView::Run() Line 68 C++
      twinapi.dll!Windows::ApplicationModel::Core::CoreApplicationView::Run() Line 808 C++
      twinapi.dll!`Windows::ApplicationModel::Core::CoreApplicationViewAgileContainer::RuntimeClassInitialize'::`55'::<lambda_C91BC4E451DFC06D>::operator()(void * pv) Line 476 C++
      twinapi.dll!`Windows::ApplicationModel::Core::CoreApplicationViewAgileContainer::RuntimeClassInitialize'::`55'::<lambda_C91BC4E451DFC06D>::<helper_func>(void * pv) Line 526 C++
      SHCore.dll!_PathIsNetworkPathW@4() Unknown
      kernel32.dll!@BaseThreadInitThunk@12() Unknown
      ntdll.dll!___RtlUserThreadStart@8() Unknown
      ntdll.dll!__RtlUserThreadStart@8() Unknown



    Software Engineer, Brainium Studios LLC



    Tuesday, May 15, 2012 6:26 PM
  • Brent,

    Once again, thanks for reporting this. This looks like issue to do with STA reentrancy. Is there a different thread in the process that has a smiliar stack at the time of this stack overflow? If so can you paste that stack here as well.

    --Geni

    Wednesday, May 16, 2012 6:50 PM
  • There are hundreds of threads, but I examined several of them (and at least each unique location once) and didn't find any other threads that looked unusual. I've uploaded a dump to Dropbox that's 306MB if you want to take a look at it. http://dl.dropbox.com/u/76772406/Jumbline2Win.dmp


    Software Engineer, Brainium Studios LLC

    Wednesday, May 16, 2012 10:07 PM
  • Thanks. I'll take a look.
    Thursday, May 17, 2012 4:54 PM
  • I will also need a .pdb for Jumbline2Win. Public symbols will do.
    Thursday, May 17, 2012 5:23 PM
  • I don't really need the symbols. Could you just paste the stack of one of the threadpool threads that is dispatching a call back to the UI thread (has combase.dll!MTAThreadDispatchCrossApartmentCall on the stack towards the very top).

    There were some bugs around re-entrancy that we have fixed since CP as well. After our next public release I should be able to give you a workaround to see if that fixes your issue.

    In the meantime, I take it Load starts up one of these async operations that produces a PixelDataProvider* - if the continuation/completion for those opreations don't need to run on the UI thread you could use task_continuation_context::use_arbitrary() to prevent them from calling back and reentering on the main UI thread. Of course, if you need them to run on the UI thread my suggestion is moot.

    --Geni

    Thursday, May 17, 2012 5:38 PM
  • Sorry it took so long for me to get back to you (was away). I'm working on migrating to the RC, and still getting some issues. The call stack for a worker thread named ntdll.dll!_TppWorkerThread@4() is below. I've also uploaded a zip with a new dump and symbols, including a dump for failure despite trying use_arbitrary. It may be worth noting that the exact location of failure seems to vary with the RC. Sometimes it's a stack overflow, occasionally I get "An invalid parameter was passed to a function that considers invalid parameters fatal," as is the case with the use_arbitrary dump. Last thing: I can usually get a few to a couple dozen runs in the debugger before this starts to appear. After the first failure, it fails on every run. Rebooting solves it temporarily.

     	ntdll.dll!_NtWaitForSingleObject@12()	Unknown
     	KernelBase.dll!_WaitForSingleObjectEx@12()	Unknown
     	KernelBase.dll!_WaitForSingleObject@8()	Unknown
     	combase.dll!MTAThreadWaitForCall(CMessageCall * pCall, WaitForCallReason reason, unsigned long dwRetryTimeout) Line 5069	C++
     	combase.dll!MTAThreadDispatchCrossApartmentCall(OXIDEntry * pOXIDEntry, CMessageCall * pCall) Line 186	C++
     	combase.dll!CRpcChannelBuffer::SendReceive2(tagRPCOLEMESSAGE * pMessage, unsigned long * pstatus)	C++
     	combase.dll!DefaultSendReceive(CAptRpcChnl * pChannel, tagRPCOLEMESSAGE * pMsg, unsigned long * pulStatus) Line 671	C++
     	combase.dll!CCtxComChnl::SendReceive(tagRPCOLEMESSAGE * pMessage, unsigned long * pulStatus) Line 725	C++
     	combase.dll!NdrExtpProxySendReceive(void * pThis, _MIDL_STUB_MESSAGE * pStubMsg) Line 1948	C++
     	rpcrt4.dll!@NdrpProxySendReceive@4()	Unknown
     	rpcrt4.dll!_NdrClientCall2()	Unknown
     	combase.dll!ObjectStublessClient(void * ParamAddress, long Method) Line 474	C++
     	combase.dll!_ObjectStubless@0() Line 154	Unknown
     	combase.dll!CObjectContext::InternalContextCallback(HRESULT (void *) * pfnCallback, void * pParam, const _GUID & riid, int iMethod, IUnknown * pUnk) Line 4428	C++
     	combase.dll!CObjectContext::ContextCallback(HRESULT (tagComCallData *) * pfnCallback, tagComCallData * pParam, const _GUID & riid, int iMethod, IUnknown * pUnk) Line 4330	C++
    >	Jumbline2Win.exe!Concurrency::details::_ContextCallback::_CallInContext(std::function<void __cdecl(void)> _Func) Line 596	C++
     	Jumbline2Win.exe!<lambda_cee1ccae03fc586a373dbff14d6ec100>::operator()() Line 1699	C++
     	Jumbline2Win.exe!std::_Callable_obj<<lambda_cee1ccae03fc586a373dbff14d6ec100>,0>::_ApplyX<void>() Line 431	C++
     	Jumbline2Win.exe!std::_Func_impl<std::_Callable_obj<<lambda_cee1ccae03fc586a373dbff14d6ec100>,0>,std::allocator<std::_Func_class<void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil> >,void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil>::_Do_call() Line 239	C++
     	Jumbline2Win.exe!std::_Func_class<void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil>::operator()() Line 514	C++
     	Jumbline2Win.exe!Concurrency::details::_ScheduleFuncWithAutoInline(const std::function<void __cdecl(void)> & _Func, Concurrency::details::_TaskInliningMode _InliningMode) Line 484	C++
     	Jumbline2Win.exe!Concurrency::details::_Task_impl_base::_ScheduleContinuationTask(Concurrency::details::_ContinuationTaskHandleBase * _PTaskHandle) Line 1679	C++
     	Jumbline2Win.exe!Concurrency::details::_Task_impl_base::_RunContinuation(Concurrency::details::_ContinuationTaskHandleBase * _PTaskHandle) Line 1657	C++
     	Jumbline2Win.exe!Concurrency::details::_Task_impl_base::_RunTaskContinuations() Line 1811	C++
     	Jumbline2Win.exe!Concurrency::details::_Task_impl<Windows::Graphics::Imaging::BitmapFrame ^>::_FinalizeAndRunContinuations(Windows::Graphics::Imaging::BitmapFrame ^ _Result) Line 2107	C++
     	Jumbline2Win.exe!<lambda_7046753f85c21446440cab4d0c251f76>::operator()(Windows::Foundation::IAsyncOperation<Windows::Graphics::Imaging::BitmapFrame ^> ^ _Operation, Windows::Foundation::AsyncStatus _Status) Line 1877	C++
     	Jumbline2Win.exe!`Windows::Foundation::AsyncOperationCompletedHandler<Windows::Graphics::Imaging::BitmapFrame ^>::AsyncOperationCompletedHandler<Windows::Graphics::Imaging::BitmapFrame ^><<lambda_7046753f85c21446440cab4d0c251f76> >'::`2'::__abi_FunctorCapture::Invoke(Windows::Foundation::IAsyncOperation<Windows::Graphics::Imaging::BitmapFrame ^> ^ __param0, Windows::Foundation::AsyncStatus __param1)	C++
     	Jumbline2Win.exe!Windows::Foundation::AsyncOperationCompletedHandler<Windows::Graphics::Imaging::BitmapFrame ^>::Invoke(Windows::Foundation::IAsyncOperation<Windows::Graphics::Imaging::BitmapFrame ^> ^ __param0, Windows::Foundation::AsyncStatus __param1)	C++
     	Jumbline2Win.exe!?__abi_Windows_Foundation_?$AsyncOperationCompletedHandler@P$AAVBitmapFrame@Imaging@Graphics@Windows@@___abi_IDelegate____abi_Invoke@?Q__abi_IDelegate@?$AsyncOperationCompletedHandler@P$AAVBitmapFrame@Imaging@Graphics@Windows@@@Foundation@Windows@@234@U$AAGJP$AAU?$IAsyncOperation@P$AAVBitmapFrame@Imaging@Graphics@Windows@@@34@W4AsyncStatus@34@@Z(Windows::Foundation::IAsyncOperation<Windows::Graphics::Imaging::BitmapFrame ^> ^ __param0, Windows::Foundation::AsyncStatus __param1)	C++
     	Windows.Graphics.dll!6459f3a0()	Unknown
     	[Frames below may be incorrect and/or missing, no symbols loaded for Windows.Graphics.dll]	
     	Windows.Graphics.dll!6459f46c()	Unknown
     	ntdll.dll!_RtlpTpWorkCallback@8()	Unknown
     	ntdll.dll!_TppWorkerThread@4()	Unknown
     	kernel32.dll!@BaseThreadInitThunk@12()	Unknown
     	ntdll.dll!___RtlUserThreadStart@8()	Unknown
     	ntdll.dll!__RtlUserThreadStart@8()	Unknown

    Software Engineer, Brainium Studios LLC



    Friday, June 15, 2012 7:09 PM
  • Brent

    Here's a suggestion for you to try on the RP version. First save your copy of ppltasks.h to a safe location, so you can restore it later, before making the change I suggest below.

    In the _CallInContext method of the _ContextCallback class under Concurrency::details in ppltasks.h modify the line below:

    HRESULT _Hr = _M_context._M_pContextCallback->ContextCallback(&_Bridge, &callData, IID_IContextCallback, 5, nullptr);

    to be

    HRESULT _Hr = _M_context._M_pContextCallback->ContextCallback(&_Bridge, &callData, IID_ICallbackWithNoReentrancyToApplicationSTA, 5, nullptr);

    Revert back the use_arbitrary change, then rebuild your project (it may not detect that ppltasks.h has changed out from under it). You will have to undo the read only attribute on ppltasks.h and open it with an editor that was started as Administrator. Let me know if that changes the situation with the stack overflow.

    I will take a look at your dump next. If you're seeing the message "An invalid parameter was passed to a function that considers invalid parameters fatal", from my experience this is an indication that a c++ exception tried to escape the ABI boundary. Try turning on first chance exceptions in the debugger to see if you can catch that earlier. Yes, I am aware that particular error message is not helpful. If you look further down in the stack, you may be able to spot where the exception is being thrown.

    Friday, June 15, 2012 11:24 PM
  • A quick look at the new dump shows that some code in Jumbline2Win is throwing  a c++ exception, as I suspected.
    Friday, June 15, 2012 11:37 PM