1

I used the following C++ functions to lock 1 byte of a file that is shared by server via SMB:

On Windows:

LockFileEx (h, LOCKFILE_FAIL_IMMEDIATELY | LOCKFILE_EXCLUSIVE_LOCK, 0, 1,0, &overlapped)

On Linux and Mac OS:

fcntl (fd, F_SETLK, &flockdesc)

On both locally shared files, and for a file shared over SMB, I got a successful lock in just 3 microseconds, whereas, for a file shared over NFS, I got a successful lock on the file in 26 milliseconds.

I am unable to understand how a process could get a lock in 3 microseconds over a network, since, to communicate to a server it should take at least some milliseconds of time, as observed in case of File shared over NFS.

Could anyone help me figure out why this is happening?

Hemanth Kumar
  • 314
  • 2
  • 7

1 Answers1

1

It is happening because Windows is using oplocks for locking -> https://learn.microsoft.com/en-us/windows-hardware/drivers/ifs/oplock-overview

Przemek
  • 11
  • 1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/549063) – Dave M Apr 22 '23 at 11:39