[cfe-dev] [libclang] thread safety issue

Ranjeet Singh via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 30 08:37:30 PDT 2017

Hi Alex,

thanks for the quick response.

Yes that answers my question. I'll investigate the thread-safety issues and will decide if it's worth trying to make libclang thread-safe.



From: Alex L <arphaman at gmail.com>
Sent: 30 March 2017 15:34:28
To: Ranjeet Singh
Cc: cfe-dev at lists.llvm.org; nd
Subject: Re: [cfe-dev] [libclang] thread safety issue

AFAIK CIndex is not thread-safe in general, so it's probably not worth fixing. Note that even though the implementation of CIndex might dispatch work to other threads, it will actually wait for them to complete, so it won't race as long as its API is used by a single thread.

I hope this helps,

On 30 March 2017 at 15:23, Ranjeet Singh via cfe-dev <cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>> wrote:


I've found a potential race condition that can happen in the following code on variable ResourcesPath in tools/libclang/CIndexer.cpp

const std::string &CIndexer::getClangResourcesPath() {
  // Did we already compute the path?
  if (!ResourcesPath.empty())
    return ResourcesPath;

  SmallString<128> LibClangPath;

  // Cache our result.
  ResourcesPath = LibClangPath.str();
  return ResourcesPath;

Variable ResourcesPath isn't synchronized on so it's possible that another thread might update ResourcesPath at the same time. Is it worth fixing this or is libclang advertised as not thread-safe so it's not worth fixing these types of bugs ?



cfe-dev mailing list
cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170330/87fe36f8/attachment.html>

More information about the cfe-dev mailing list