Attempt to solve race condition with lock files.
If lock_file returns status < 0, do several iterations of sleeping for a short duration and checking again whether the lockfile can be created.
This seems to fix the problem I have been having with knitr and tikz.