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

Adrian McCarthy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 29 09:06:15 PDT 2020


amccarth added a comment.

If the goal is to synchronize writes to a highly contended log file, would it be better (and feasible) to have the individual threads/processes write timestamped output to separate streams that can be merged after-the-fact?



================
Comment at: llvm/lib/Support/Windows/Path.inc:1276
+      if (Error == ERROR_LOCK_VIOLATION) {
+        ::Sleep(1);
+        continue;
----------------
`::Sleep(1)` sleeps for _at least_ one millisecond, but possibly for much longer.  The default tick frequency on Windows is about 16 ms.  (Many apps boost the system's timer frequency to 1 ms, but that's not universal and not recommended except for short periods when an app needs to display real-time media.)

Sleeping too long once isn't a big deal.  But Counter increments by 1 ms each time through the loop, regardless of how long it actually took, so this is likely to sleep too long many times.  If the user requests a 10 ms timeout, they could actually wait 160 ms (in some near-worst case scenario).

If this tracked the actual time elapsed, it probably would never be worse than 16 ms.

You can use chrono's high resolution clock or Windows APIs like ::GetTickCount or ::QueryPerformanceCounter to find out how long the thread actually slept.


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