remove race condition around closing channel by use of CAS