Add THREAD_FLAGS_EXIT_ON_IRQ for preempted threads

Adds a THREAD_FLAGS_EXIT_ON_IRQ flag to the saved state of a thread
to make it possible to check that no other thread may resume if there's
a thread preempted by an IRQ.