From f02f23eff5108c2dbdd22c2853879dc0f49602c2 Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Tue, 26 Sep 2017 05:54:53 +0200 Subject: [PATCH] Add STACK_SIZE_PARAM_IS_A_RESERVATION when setting the stack size. --- src/win32/thread.cpp | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/win32/thread.cpp b/src/win32/thread.cpp index 3d9fc88f..2d2a52c2 100644 --- a/src/win32/thread.cpp +++ b/src/win32/thread.cpp @@ -3,7 +3,7 @@ // http://www.boost.org/LICENSE_1_0.txt) // (C) Copyright 2007 Anthony Williams // (C) Copyright 2007 David Deakins -// (C) Copyright 2011-2013 Vicente J. Botet Escriba +// (C) Copyright 2011-2017 Vicente J. Botet Escriba //#define BOOST_THREAD_VERSION 3 @@ -154,8 +154,6 @@ namespace boost return ret; } - //typedef void* uintptr_t; - inline uintptr_t _beginthreadex(void* security, unsigned stack_size, unsigned (__stdcall* start_address)(void*), void* arglist, unsigned initflag, unsigned* thrdaddr) { @@ -299,12 +297,7 @@ namespace boost BOOST_CATCH(thread_interrupted const&) { } -// Removed as it stops the debugger identifying the cause of the exception -// Unhandled exceptions still cause the application to terminate -// BOOST_CATCH(...) -// { -// std::terminate(); -// } + // Unhandled exceptions still cause the application to terminate BOOST_CATCH_END #endif run_thread_exit_callbacks(); @@ -322,7 +315,6 @@ namespace boost if (!thread_info->thread_handle.start(&thread_start_function, thread_info.get(), &thread_info->id)) { intrusive_ptr_release(thread_info.get()); -// boost::throw_exception(thread_resource_error()); return false; } return true; @@ -331,7 +323,6 @@ namespace boost if(!new_thread) { return false; -// boost::throw_exception(thread_resource_error()); } intrusive_ptr_add_ref(thread_info.get()); thread_info->thread_handle=(detail::win32::handle)(new_thread); @@ -347,12 +338,11 @@ namespace boost attr; return start_thread_noexcept(); #else - //uintptr_t const new_thread=_beginthreadex(attr.get_security(),attr.get_stack_size(),&thread_start_function,thread_info.get(),CREATE_SUSPENDED,&thread_info->id); - uintptr_t const new_thread=_beginthreadex(0,static_cast(attr.get_stack_size()),&thread_start_function,thread_info.get(),CREATE_SUSPENDED,&thread_info->id); + uintptr_t const new_thread=_beginthreadex(0,static_cast(attr.get_stack_size()),&thread_start_function,thread_info.get(), + CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION, &thread_info->id); if(!new_thread) { return false; -// boost::throw_exception(thread_resource_error()); } intrusive_ptr_add_ref(thread_info.get()); thread_info->thread_handle=(detail::win32::handle)(new_thread); @@ -644,7 +634,6 @@ namespace boost } Detailed; } Reason; } REASON_CONTEXT, *PREASON_CONTEXT; - //static REASON_CONTEXT default_reason_context={0/*POWER_REQUEST_CONTEXT_VERSION*/, 0x00000001/*POWER_REQUEST_CONTEXT_SIMPLE_STRING*/, (LPWSTR)L"generic"}; typedef BOOL (WINAPI *setwaitabletimerex_t)(HANDLE, const LARGE_INTEGER *, LONG, PTIMERAPCROUTINE, LPVOID, PREASON_CONTEXT, ULONG); static inline BOOL WINAPI SetWaitableTimerEx_emulation(HANDLE hTimer, const LARGE_INTEGER *lpDueTime, LONG lPeriod, PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, PREASON_CONTEXT WakeContext, ULONG TolerableDelay) { @@ -714,7 +703,6 @@ namespace boost if(time_left.milliseconds/20>tolerable) // 5% tolerable=time_left.milliseconds/20; LARGE_INTEGER due_time=get_due_time(target_time); - //bool const set_time_succeeded=detail_::SetWaitableTimerEx()(timer_handle,&due_time,0,0,0,&detail_::default_reason_context,tolerable)!=0; bool const set_time_succeeded=detail_::SetWaitableTimerEx()(timer_handle,&due_time,0,0,0,NULL,tolerable)!=0; if(set_time_succeeded) { @@ -799,7 +787,6 @@ namespace boost if(time_left.milliseconds/20>tolerable) // 5% tolerable=time_left.milliseconds/20; LARGE_INTEGER due_time=get_due_time(target_time); - //bool const set_time_succeeded=detail_::SetWaitableTimerEx()(timer_handle,&due_time,0,0,0,&detail_::default_reason_context,tolerable)!=0; bool const set_time_succeeded=detail_::SetWaitableTimerEx()(timer_handle,&due_time,0,0,0,NULL,tolerable)!=0; if(set_time_succeeded) { @@ -1028,16 +1015,5 @@ namespace boost current_thread_data->notify_all_at_thread_exit(&cond, lk.release()); } } -//namespace detail { -// -// void BOOST_THREAD_DECL make_ready_at_thread_exit(shared_ptr as) -// { -// detail::thread_data_base* const current_thread_data(detail::get_current_thread_data()); -// if(current_thread_data) -// { -// current_thread_data->make_ready_at_thread_exit(as); -// } -// } -//} }