Commit 7ea924c7 authored by Simon Giesecke's avatar Simon Giesecke Committed by Luca Boccassi

Problem: segfault on thread_t::stop if thread was never started

Solution: add started flag
parent 56c726d4
......@@ -59,14 +59,17 @@ void zmq::thread_t::start (thread_fn *tfn_, void *arg_)
(HANDLE) _beginthreadex (NULL, 0, &::thread_routine, this, 0, NULL);
#endif
win_assert (descriptor != NULL);
started = true;
}
void zmq::thread_t::stop ()
{
DWORD rc = WaitForSingleObject (descriptor, INFINITE);
win_assert (rc != WAIT_FAILED);
BOOL rc2 = CloseHandle (descriptor);
win_assert (rc2 != 0);
if (started) {
DWORD rc = WaitForSingleObject (descriptor, INFINITE);
win_assert (rc != WAIT_FAILED);
BOOL rc2 = CloseHandle (descriptor);
win_assert (rc2 != 0);
}
}
void zmq::thread_t::setSchedulingParameters (
......@@ -116,12 +119,15 @@ void zmq::thread_t::start (thread_fn *tfn_, void *arg_)
arg = arg_;
int rc = pthread_create (&descriptor, NULL, thread_routine, this);
posix_assert (rc);
started = true;
}
void zmq::thread_t::stop ()
{
int rc = pthread_join (descriptor, NULL);
posix_assert (rc);
if (started) {
int rc = pthread_join (descriptor, NULL);
posix_assert (rc);
}
}
void zmq::thread_t::setSchedulingParameters (
......
......@@ -52,6 +52,7 @@ class thread_t
inline thread_t () :
tfn (NULL),
arg (NULL),
started (false),
thread_priority (ZMQ_THREAD_PRIORITY_DFLT),
thread_sched_policy (ZMQ_THREAD_SCHED_POLICY_DFLT)
{
......@@ -81,6 +82,8 @@ class thread_t
void *arg;
private:
bool started;
#ifdef ZMQ_HAVE_WINDOWS
HANDLE descriptor;
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment