Fixed keepalive_thread() to use a local condition and mutex.