A simple and effective locking scheme is to place an operating system "lock" around every critical piece of code. If you have too much going on though the locks will get "hot" and the entire test platform will run slowly.
If a row needs to be locked for a while, a row lock can be used. A row lock has you designate a column to manage concurrency (say, the RowStatus column). The value of the RowStatus column indicates whether the row is allocated to a specific thread / process: ("<something>" = allocated) or not ("" = "free"). The threads / processes must use a convention to atomically allocate and free the row. See routine "Background.allocateAnAnimal" in animalFarm_02 for an example.