One approach to make parallel sed -i on the same file thread safe, starting from the context given by user313992 would be to use a simple Advisory lock.
flock $theSharedFile sed -i s/$userInput1/$userInput2/g $theSharedFile
Flock creates and advisory lock on it first argument, and will execute the command with the rest of the arguments when the lock is free (when no other flock is running for that same file).
If two different users trigger it at same time, the second one will wait until the previous ones end. Like that it will be a fully functional and thread safe approach.
Since it is an advisory lock, it will only be significant for flock, and should not cause any kind of deadlock. Notice if file is large it can be expected to take significant amount of time of waiting for the processes waiting for the lock.
You can list current locks with lslocks