[PATCH] D78896: [Support] Add file lock/unlock functions

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 8 08:48:56 PDT 2020


MaskRay added inline comments.


================
Comment at: llvm/lib/Support/Unix/Path.inc:1066
+      return std::error_code(Error, std::generic_category());
+    usleep(1000);
+  } while (std::chrono::steady_clock::now() < End);
----------------
labath wrote:
> MaskRay wrote:
> > I feel uneasy with usleep(1000). Why is it needed?
> That's because the os provides no mechanism to wait for a lock to become available for a given amount of time (well.... one could use `SIGALRM`s to achieve that, but those come with problems of their own..)
> 
> Using exponential backoff for this might be a good idea, but I also think that can wait until this becomes a problem.
The standard `try_*` (std::mutex::try_lock, pthread_mutex_trylock, etc) return immediately upon a failure. The backoff strategy should be done by the application to avoid the misnomer.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78896/new/

https://reviews.llvm.org/D78896





More information about the llvm-commits mailing list