Fix two crashes Isaac found during stress testing.

We must check if the main thread has exited before checking if the end has been hit
in the container's iterator class or else we can crash there. Also, only look for the
next item once.
In modify_job_attr() we need to check if the job is NULL before dereferencing after a failed
call to get_jobs_queue().