Skip to content

Instantly share code, notes, and snippets.

@privefl
Last active December 13, 2017 08:19
Show Gist options
  • Save privefl/fca97600eac422681aa5b52c0bfd4f7e to your computer and use it in GitHub Desktop.
Save privefl/fca97600eac422681aa5b52c0bfd4f7e to your computer and use it in GitHub Desktop.
#### IN ORDER ####
# In first session, run:
write(1, "test.txt")
obj.lock <- flock::lock("test.txt")
# In second session, run this (this will wait the unlock in the first session)
obj.lock <- flock::lock("test.txt")
write(2, "test.txt", append = TRUE)
flock::unlock(obj.lock)
# Then run this in first session (session 2 will run when unlocking)
write(3, "test.txt", append = TRUE)
flock::unlock(obj.lock)
# Verif in any session (3 is written before 2)
readLines("test.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment