At line 795 of libzwaveip.c (in zclient_stop) there is a TODO comment referring to a "mystery" failure when using pthread_join().
The thread calls pthread_detach() (line 406), marking it as detached, which means that when the thread exits its resources will automatically be released. This makes the pthread_join() call redundant. Trying to join a thread marked as detached will result in an error.