Opened 11 years ago
Closed 11 years ago
#5843 closed Bugs (invalid)
thread.cpp: thread::join() does not throw for a non-joinable thread
| Reported by: | Owned by: | viboes | |
|---|---|---|---|
| Milestone: | Component: | thread | |
| Version: | Boost 1.47.0 | Severity: | Problem |
| Keywords: | Cc: | viboes |
Description
Boost uses non-joinable threads. For example, under Windows:
thread::thread() : m_joinable(false)
{
m_thread = reinterpret_cast<void*>(GetCurrentThread());
m_id = GetCurrentThreadId();
}
The thread::join() properly asserts the property, but still attempts to join a non-joinable thread:
void thread::join()
{
assert(m_joinable); //See race condition comment below
int res = 0;
res = WaitForSingleObject(reinterpret_cast<HANDLE>(m_thread), INFINITE);
assert(res == WAIT_OBJECT_0);
res = CloseHandle(reinterpret_cast<HANDLE>(m_thread));
assert(res);
// This isn't a race condition since any race that could occur would
// have us in undefined behavior territory any way.
m_joinable = false;
}
Related to https://svn.boost.org/trac/boost/ticket/5838 and https://svn.boost.org/trac/boost/ticket/5842.
Change History (5)
comment:1 by , 11 years ago
| Component: | None → thread |
|---|---|
| Owner: | set to |
comment:2 by , 11 years ago
| Cc: | added |
|---|
I don't know IIUC the interface, but IMO, a thread that has already finished can not be joined. Do you agree with my understanding?
Preconditions:
this->get_id()!=boost::this_thread::get_id()
Effects:
If *this refers to a thread of execution, waits for that thread of execution to complete.
Postconditions:
If *this refers to a thread of execution on entry, that thread of execution has completed. *this no longer refers to any thread of execution.
Throws:
boost::thread_interrupted if the current thread of execution is interrupted.
Notes:
join() is one of the predefined interruption points.
comment:3 by , 11 years ago
| Cc: | removed |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:4 by , 11 years ago
| Cc: | added |
|---|---|
| Type: | Bugs → Support Requests |
Moved to support until the resolution is clarified.
comment:5 by , 11 years ago
| Milestone: | To Be Determined |
|---|---|
| Resolution: | → invalid |
| Status: | assigned → closed |
| Type: | Support Requests → Bugs |

assert(res == WAIT_OBJECT_0)might be too tight -assert(res == WAIT_OBJECT_0 || res == WAIT_ABANDONED_0)might be a better choice.