mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 10:52:56 +01: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);
|
||||
#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
|
||||
|
Loading…
Reference in New Issue
Block a user