mirror of
https://github.com/zeromq/libzmq.git
synced 2025-07-05 18:01:41 +02:00
Problem: segfault on thread_t::stop if thread was never started
Solution: add started flag
This commit is contained in:
parent
56c726d425
commit
7ea924c763
@ -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 ()
|
||||||
{
|
{
|
||||||
|
if (started) {
|
||||||
DWORD rc = WaitForSingleObject (descriptor, INFINITE);
|
DWORD rc = WaitForSingleObject (descriptor, INFINITE);
|
||||||
win_assert (rc != WAIT_FAILED);
|
win_assert (rc != WAIT_FAILED);
|
||||||
BOOL rc2 = CloseHandle (descriptor);
|
BOOL rc2 = CloseHandle (descriptor);
|
||||||
win_assert (rc2 != 0);
|
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_)
|
|||||||
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 ()
|
||||||
{
|
{
|
||||||
|
if (started) {
|
||||||
int rc = pthread_join (descriptor, NULL);
|
int rc = pthread_join (descriptor, NULL);
|
||||||
posix_assert (rc);
|
posix_assert (rc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void zmq::thread_t::setSchedulingParameters (
|
void zmq::thread_t::setSchedulingParameters (
|
||||||
|
@ -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
|
|||||||
void *arg;
|
void *arg;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool started;
|
||||||
|
|
||||||
#ifdef ZMQ_HAVE_WINDOWS
|
#ifdef ZMQ_HAVE_WINDOWS
|
||||||
HANDLE descriptor;
|
HANDLE descriptor;
|
||||||
#else
|
#else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user