Handle exiting more gracefully

Set all threads to daemon mode and close
the write end of the pipe when exiting to
ensure we cleanup in a friendly manner.

Change-Id: I4cf64fa39e820c95d11943b848db87e5db15212e