No
memory_order
would prevent this code from calling need_close()
more than once. Also I suggest replacing rand()
with something else (something thread-safe), if your question is not specifically about it.