Skip to content

Commit

Permalink
Crash issue while calling run_thread_exit_callbacks. Related to #11053.
Browse files Browse the repository at this point in the history
  • Loading branch information
viboes committed Mar 1, 2015
1 parent e0ce8af commit c678b37
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 17 deletions.
9 changes: 3 additions & 6 deletions src/pthread/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,10 @@ namespace boost
}
delete current_node;
}
for(std::map<void const*,tss_data_node>::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<void const*,detail::tss_data_node>::iterator current
= thread_info->tss_data.begin();
if(current->second.func && (current->second.value!=0))
{
(*current->second.func)(current->second.value);
Expand Down
19 changes: 8 additions & 11 deletions src/win32/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include <wrl\ftm.h>
#include <windows.system.threading.h>
#pragma comment(lib, "runtimeobject.lib")
#endif
#endif

namespace boost
{
Expand Down Expand Up @@ -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<ABI::Windows::System::Threading::IThreadPoolStatics> threadPoolFactory;
Expand All @@ -220,7 +220,7 @@ namespace boost
m_completionHandle = completionHandle;

// Create new work item.
Microsoft::WRL::ComPtr<ABI::Windows::System::Threading::IWorkItemHandler> workItem =
Microsoft::WRL::ComPtr<ABI::Windows::System::Threading::IWorkItemHandler> workItem =
Microsoft::WRL::Callback<Microsoft::WRL::Implements<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, ABI::Windows::System::Threading::IWorkItemHandler, Microsoft::WRL::FtmBase>>
([address, parameter, completionHandle](ABI::Windows::Foundation::IAsyncAction *)
{
Expand Down Expand Up @@ -274,13 +274,10 @@ namespace boost
}
boost::detail::heap_delete(current_node);
}
for(std::map<void const*,detail::tss_data_node>::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<void const*,detail::tss_data_node>::iterator current
= current_thread_data->tss_data.begin();
if(current->second.func && (current->second.value!=0))
{
(*current->second.func)(current->second.value);
Expand Down Expand Up @@ -346,7 +343,7 @@ namespace boost
return true;
#endif
}

bool thread::start_thread_noexcept(const attributes& attr)
{
#if BOOST_PLAT_WINDOWS_RUNTIME
Expand All @@ -367,7 +364,7 @@ namespace boost
return true;
#endif
}

thread::thread(detail::thread_data_ptr data):
thread_info(data)
{}
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
;


Expand Down
70 changes: 70 additions & 0 deletions test/test_11053.cpp
Original file line number Diff line number Diff line change
@@ -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 <boost/thread.hpp>
#include <boost/thread/tss.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>

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<WorkSpace> 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<A> 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<B> m_ptr;
};

int main(int ac, char** av)
{
std::cout << "test starting\n";
boost::shared_ptr<C> p_C(new C);
boost::thread cWorker(&C::DoWork, p_C);
cWorker.join();
std::cout << "test stopping\n";
return 0;
}



0 comments on commit c678b37

Please sign in to comment.