Skip to content

Instantly share code, notes, and snippets.

@anibal
Created July 29, 2010 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anibal/499497 to your computer and use it in GitHub Desktop.
Save anibal/499497 to your computer and use it in GitHub Desktop.
fh = File.new("file.txt")
while(true)
begin
puts "WITHOUT lock"
sleep(rand(5))
fh.flock(File::LOCK_EX)
puts "WITH lock"
sleep(rand(5))
ensure
fh.flock(File::LOCK_UN)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment