[PATCH] D58246: [lld] Fix elf::unlinkAsync detached thread
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 14 15:30:05 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL354078: [lld] Fix elf::unlinkAsync detached thread (authored by vitalybuka, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D58246?vs=186920&id=186929#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D58246/new/
https://reviews.llvm.org/D58246
Files:
lld/trunk/ELF/Filesystem.cpp
Index: lld/trunk/ELF/Filesystem.cpp
===================================================================
--- lld/trunk/ELF/Filesystem.cpp
+++ lld/trunk/ELF/Filesystem.cpp
@@ -58,9 +58,26 @@
std::error_code EC = sys::fs::openFileForRead(Path, FD);
sys::fs::remove(Path);
+ if (EC)
+ return;
+
// close and therefore remove TempPath in background.
- if (!EC)
- std::thread([=] { ::close(FD); }).detach();
+ std::mutex M;
+ std::condition_variable CV;
+ bool Started = false;
+ std::thread([&, FD] {
+ {
+ std::lock_guard<std::mutex> L(M);
+ Started = true;
+ CV.notify_all();
+ }
+ ::close(FD);
+ }).detach();
+
+ // GLIBC 2.26 and earlier have race condition that crashes an entire process
+ // if the main thread calls exit(2) while other thread is starting up.
+ std::unique_lock<std::mutex> L(M);
+ CV.wait(L, [&] { return Started; });
#endif
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58246.186929.patch
Type: text/x-patch
Size: 902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190214/222a643c/attachment.bin>
More information about the llvm-commits
mailing list