Using atomic operations to emulate rwlock