grabs lock
writes to file
writes to index
releases lock
That's not a race condition. The output order doesn't matter, but it is nondeterministic.