<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">In that line:<div class=""><br class=""></div><div class=""><div class="">if (FileNode *node = dyn_cast<FileNode>(nodes[i].get())) </div><div class=""><br class=""></div><div class="">What happen if, between the call to nodes[i] and the call to ‘get()’, the vector is resized (by a call to parse() performed on a spawned task) ? Couldn’t the resizing invalidate the unique_ptr reference ?</div><div class=""><br class=""></div><div class="">Moreover, AFAIK std::vector member access is not thread safe, so even nodes[i] may fail if the vector can be resized concurrently by background parsing thread.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Le 23 janv. 2015 à 19:58, Rui Ueyama <<a href="mailto:ruiu@google.com" class="">ruiu@google.com</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">The list of nodes the context object has is a shared resource -- by parsing a file, the parser may add more files to the input list. (That doesn't occur for ELF but may occur for COFF, since a COFF object may contain extra command line parameters which let the linker to read more files.)</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Jan 23, 2015 at 8:17 AM, Jean-Daniel Dupas <span dir="ltr" class=""><<a href="mailto:dev@xenonium.com" target="_blank" class="">dev@xenonium.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Does it not reveal a race condition here ?<br class="">
An action preformed in background by the thread pool should not affect the behavior of the current thread.<br class="">
<br class="">
> Le 23 janv. 2015 à 01:09, Rui Ueyama <<a href="mailto:ruiu@google.com" class="">ruiu@google.com</a>> a écrit :<br class="">
<div class="HOEnZb"><div class="h5">><br class="">
> Author: ruiu<br class="">
> Date: Thu Jan 22 18:09:05 2015<br class="">
> New Revision: 226883<br class="">
><br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=226883&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=226883&view=rev</a><br class="">
> Log:<br class="">
> Make access to LinkingContext::getNode safe.<br class="">
><br class="">
> Modified:<br class="">
>    lld/trunk/lib/Driver/Driver.cpp<br class="">
><br class="">
> Modified: lld/trunk/lib/Driver/Driver.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=226883&r1=226882&r2=226883&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=226883&r1=226882&r2=226883&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- lld/trunk/lib/Driver/Driver.cpp (original)<br class="">
> +++ lld/trunk/lib/Driver/Driver.cpp Thu Jan 22 18:09:05 2015<br class="">
> @@ -77,8 +77,11 @@ bool Driver::link(LinkingContext &contex<br class="">
>   if (context.getNodes().empty())<br class="">
>     return false;<br class="">
><br class="">
> -  for (std::unique_ptr<Node> &ie : context.getNodes())<br class="">
> -    if (FileNode *node = dyn_cast<FileNode>(ie.get()))<br class="">
> +  // File::parse may add items to the node list which may invalidate<br class="">
> +  // existing iterators. Avoid using iterator to access elements.<br class="">
> +  std::vector<std::unique_ptr<Node>> &nodes = context.getNodes();<br class="">
> +  for (size_t i = 0; i < nodes.size(); ++i)<br class="">
> +    if (FileNode *node = dyn_cast<FileNode>(nodes[i].get()))<br class="">
>       context.getTaskGroup().spawn([node] { node->getFile()->parse(); });<br class="">
><br class="">
>   std::vector<std::unique_ptr<File>> internalFiles;<br class="">
><br class="">
><br class="">
> _______________________________________________<br class="">
> llvm-commits mailing list<br class="">
> <a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class="">
<br class="">
</div></div></blockquote></div><br class=""></div>
_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br class=""></div></blockquote></div><br class=""></div></div></body></html>