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?

1 Answer 1

1

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

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
    – Dave M
    Apr 22, 2023 at 11:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .