thread.h: add atomic_exchange for int and long long

We had exchange-and-add, and compare-and-exchange, but no unconditional atomic exchange.