Fix data races, simplify cancellation signalling

/cc @titanous - Re-integrated your pull and fixed a couple races that
were even present in your pull request (specifically: reading the struct
channel structs outside of a lock and reading the state outside of a
lock). I read state outside of a lock using the atomic package now.