while condition may not be thread-safe