Use rwlock to avoid surprising results in multithreaded applications.