[libc-commits] [PATCH] D76267: [libc] Resolve race condition in sub-process test runner.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Mar 17 11:16:54 PDT 2020


sivachandra marked an inline comment as done.
sivachandra added inline comments.


================
Comment at: libc/utils/testutils/ExecuteFunctionUnix.cpp:70
   int WStatus = 0;
-  int status = ::waitpid(Pid, &WStatus, WNOHANG);
-  assert(status == Pid && "wait call should not block here");
+  pid_t status = ::waitpid(Pid, &WStatus, 0);
+  if (status == -1)
----------------
BTW, it is worth adding a comment here that `Pid` will not be recycled until the call to `waitpid` and so waiting on it is safe even after the process actually exits. Every time I read code like this, I end up having to Google for `Pid` recycling rules.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76267





More information about the libc-commits mailing list