# File lib/cloudmasterd/syncer.rb, line 47
  def self.lock
    lockfile = '/var/tmp/cloudmasterd.lock'

    begin
      # Wait until the lock is released
      while File.exists?(lockfile) do
        sleep 0.5
      end

      # Obtain the lock
      File.open(lockfile, "w") {|file| file.puts Thread.object_id.to_s}

      # Make sure the lock is ours - otherwise retry
      retry unless File.open(lockfile, "r").readline.chomp. == Thread.object_id.to_s

      # Do the lock processing
      yield
    ensure
      # Make sure to delete the lock
      File.delete(lockfile)
    end
  end