Restrict thread state transitions to avoid possible race condition.

Previously, loom_shutdown could have set a running tasks's state to
LTS_ALERT_SHUTDOWN, then clobbered it with LTS_ACTIVE when entering
run_tasks. Now, if the state is LTS_ALERT_SHUTDOWN, it stays in that
state until the thread begins shutting down and goes into LTS_CLOSING.
Also, check for shutdown before attempting to run task, not after.

Add -Wextra and fix additional warnings.
Should probably use pthread_cancel, not pthread_kill.