diff --git a/src/pthread/thread.cpp b/src/pthread/thread.cpp index d8c3c59a6..75969f725 100644 --- a/src/pthread/thread.cpp +++ b/src/pthread/thread.cpp @@ -96,13 +96,10 @@ namespace boost } delete current_node; } - for(std::map::iterator next=thread_info->tss_data.begin(), - current, - end=thread_info->tss_data.end(); - next!=end;) + while (!thread_info->tss_data.empty()) { - current=next; - ++next; + std::map::iterator current + = thread_info->tss_data.begin(); if(current->second.func && (current->second.value!=0)) { (*current->second.func)(current->second.value); diff --git a/src/win32/thread.cpp b/src/win32/thread.cpp index b4d59e131..f23cf29a1 100644 --- a/src/win32/thread.cpp +++ b/src/win32/thread.cpp @@ -44,7 +44,7 @@ #include #include #pragma comment(lib, "runtimeobject.lib") -#endif +#endif namespace boost { @@ -198,7 +198,7 @@ namespace boost namespace detail { std::atomic_uint threadCount; - + bool win32::scoped_winrt_thread::start(thread_func address, void *parameter, unsigned int *thrdId) { Microsoft::WRL::ComPtr threadPoolFactory; @@ -220,7 +220,7 @@ namespace boost m_completionHandle = completionHandle; // Create new work item. - Microsoft::WRL::ComPtr workItem = + Microsoft::WRL::ComPtr workItem = Microsoft::WRL::Callback, ABI::Windows::System::Threading::IWorkItemHandler, Microsoft::WRL::FtmBase>> ([address, parameter, completionHandle](ABI::Windows::Foundation::IAsyncAction *) { @@ -274,13 +274,10 @@ namespace boost } boost::detail::heap_delete(current_node); } - for(std::map::iterator next=current_thread_data->tss_data.begin(), - current, - end=current_thread_data->tss_data.end(); - next!=end;) + while (!current_thread_data->tss_data.empty()) { - current=next; - ++next; + std::map::iterator current + = current_thread_data->tss_data.begin(); if(current->second.func && (current->second.value!=0)) { (*current->second.func)(current->second.value); @@ -346,7 +343,7 @@ namespace boost return true; #endif } - + bool thread::start_thread_noexcept(const attributes& attr) { #if BOOST_PLAT_WINDOWS_RUNTIME @@ -367,7 +364,7 @@ namespace boost return true; #endif } - + thread::thread(detail::thread_data_ptr data): thread_info(data) {} diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 84401f19f..cb28bf7fc 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -297,6 +297,7 @@ rule thread-compile ( sources : reqs * : name ) [ thread-run test_9856.cpp ] [ thread-compile test_10963.cpp : : test_10963_c ] [ thread-run test_10964.cpp ] + [ thread-test test_11053.cpp ] ; diff --git a/test/test_11053.cpp b/test/test_11053.cpp new file mode 100644 index 000000000..a8b6dfa97 --- /dev/null +++ b/test/test_11053.cpp @@ -0,0 +1,70 @@ +// Copyright (C) 2015 Vicente Botet +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_THREAD_VERSION 4 +#include +#include +#include +#include + +struct A +{ + void DoWork() + { + std::cout << "A: doing work\n"; + if (!m_ptr.get()) + m_ptr.reset(new WorkSpace()); + // do not very much + for (size_t i = 0; i < 10; ++i) + m_ptr->a += 10; + } + +private: + struct WorkSpace + { + int a; + WorkSpace() : a(0) {} + }; + boost::thread_specific_ptr m_ptr; +}; + +struct B +{ + void DoWork() + { + std::cout << "B: doing work\n"; + if (!m_ptr.get()) + m_ptr.reset(new A()); + m_ptr->DoWork(); + } +private: + boost::thread_specific_ptr m_ptr; +}; + +struct C +{ + void DoWork() + { + std::cout << "C: doing work\n"; + if (!m_ptr.get()) + m_ptr.reset(new B()); + m_ptr->DoWork(); + } +private: + boost::thread_specific_ptr m_ptr; +}; + +int main(int ac, char** av) +{ + std::cout << "test starting\n"; + boost::shared_ptr p_C(new C); + boost::thread cWorker(&C::DoWork, p_C); + cWorker.join(); + std::cout << "test stopping\n"; + return 0; +} + + +