fix for endless wait for thread death
This commit is contained in:
@@ -87,7 +87,7 @@ class Queue {
|
|||||||
clockGettime(&t);
|
clockGettime(&t);
|
||||||
t.tv_sec += timeout;
|
t.tv_sec += timeout;
|
||||||
while (m_queue.empty()) {
|
while (m_queue.empty()) {
|
||||||
if (pthread_cond_timedwait(&m_cond, &m_mutex, &t) == ETIMEDOUT) {
|
if (pthread_cond_timedwait(&m_cond, &m_mutex, &t) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,6 +111,9 @@ class Queue {
|
|||||||
bool remove(T item, bool wait = false) {
|
bool remove(T item, bool wait = false) {
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
pthread_mutex_lock(&m_mutex);
|
pthread_mutex_lock(&m_mutex);
|
||||||
|
struct timespec t;
|
||||||
|
clockGettime(&t);
|
||||||
|
t.tv_sec++; // check thread death every second
|
||||||
do {
|
do {
|
||||||
size_t oldSize = m_queue.size();
|
size_t oldSize = m_queue.size();
|
||||||
if (oldSize > 0) {
|
if (oldSize > 0) {
|
||||||
@@ -120,7 +123,10 @@ class Queue {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_cond_wait(&m_cond, &m_mutex);
|
int ret = pthread_cond_timedwait(&m_cond, &m_mutex, &t);
|
||||||
|
if (ret != 0 && ret != ETIMEDOUT) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
} while (wait);
|
} while (wait);
|
||||||
pthread_mutex_unlock(&m_mutex);
|
pthread_mutex_unlock(&m_mutex);
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user