context: use an atomic int to handle the event thread loop