replace-object: make replace operations thread-safe