lua : change how lua works at DT exit

two phase

1) tell threads to exit and wait
.. DT kills all secondary jobs
2) close the lua state

this means that a looping thread can prevent DT from finishing
indefinitely
lua : add a field to detect when lua is exiting

This is needed to allow threads to do exit time actions and
terminate properly