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_) ...@@ -59,14 +59,17 @@ void zmq::thread_t::start (thread_fn *tfn_, void *arg_)
(HANDLE) _beginthreadex (NULL, 0, &::thread_routine, this, 0, NULL); (HANDLE) _beginthreadex (NULL, 0, &::thread_routine, this, 0, NULL);
#endif #endif
win_assert (descriptor != NULL); win_assert (descriptor != NULL);
started = true;
} }
void zmq::thread_t::stop () void zmq::thread_t::stop ()
{ {
DWORD rc = WaitForSingleObject (descriptor, INFINITE); if (started) {
win_assert (rc != WAIT_FAILED); DWORD rc = WaitForSingleObject (descriptor, INFINITE);
BOOL rc2 = CloseHandle (descriptor); win_assert (rc != WAIT_FAILED);
win_assert (rc2 != 0); BOOL rc2 = CloseHandle (descriptor);
win_assert (rc2 != 0);
}
} }
void zmq::thread_t::setSchedulingParameters ( void zmq::thread_t::setSchedulingParameters (
...@@ -116,12 +119,15 @@ void zmq::thread_t::start (thread_fn *tfn_, void *arg_) ...@@ -116,12 +119,15 @@ void zmq::thread_t::start (thread_fn *tfn_, void *arg_)
arg = arg_; arg = arg_;
int rc = pthread_create (&descriptor, NULL, thread_routine, this); int rc = pthread_create (&descriptor, NULL, thread_routine, this);
posix_assert (rc); posix_assert (rc);
started = true;
} }
void zmq::thread_t::stop () void zmq::thread_t::stop ()
{ {
int rc = pthread_join (descriptor, NULL); if (started) {
posix_assert (rc); int rc = pthread_join (descriptor, NULL);
posix_assert (rc);
}
} }
void zmq::thread_t::setSchedulingParameters ( void zmq::thread_t::setSchedulingParameters (
......
...@@ -52,6 +52,7 @@ class thread_t ...@@ -52,6 +52,7 @@ class thread_t
inline thread_t () : inline thread_t () :
tfn (NULL), tfn (NULL),
arg (NULL), arg (NULL),
started (false),
thread_priority (ZMQ_THREAD_PRIORITY_DFLT), thread_priority (ZMQ_THREAD_PRIORITY_DFLT),
thread_sched_policy (ZMQ_THREAD_SCHED_POLICY_DFLT) thread_sched_policy (ZMQ_THREAD_SCHED_POLICY_DFLT)
{ {
...@@ -81,6 +82,8 @@ class thread_t ...@@ -81,6 +82,8 @@ class thread_t
void *arg; void *arg;
private: private:
bool started;
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
HANDLE descriptor; HANDLE descriptor;
#else #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