Fix segfault during exit.

The job runners are threads that use the job queue, but when the job queue is
destroyed at program exit, the job runners continue to run. On some occasions
they were attempting to run job queue functions after the queue was destroyed,
causing the segfault. This patch addresses that by adding a mutex and a flag
that belong to the job runners, telling them that the queue is destroyed so
they avoid accessing job queue functions.

Most of the credit belongs to Robert Norris who helped with diagnosis, code
structure explanations and hints.
Merge remote-tracking branch 'pgimeno/segfaultonexit'