Skip to content

Commit

Permalink
Join a Channel thread only if possible, fix crash
Browse files Browse the repository at this point in the history
pthread_join on threads which are not joinable leads to crashes.
Channel threads are not started unconditionally.

Thus, prevent calls to pthread_join if the thread is already
joined or was never created. This fixes crashes on shutdown.
  • Loading branch information
flyingflo committed Aug 21, 2016
1 parent 15fc454 commit ac12e39
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/Channel.hpp
Expand Up @@ -56,9 +56,11 @@ class Channel {
}

void join() {
pthread_join(_thread, NULL);
_thread_running = false;
_this_forthread.reset();
if (_thread_running) {
pthread_join(_thread, NULL);
_thread_running = false;
_this_forthread.reset();
}
}

void cancel() { if (running()) pthread_cancel(_thread); }
Expand Down

0 comments on commit ac12e39

Please sign in to comment.