[libclang] thread safety issue

Hi,

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 ?

Thanks,

Ranjeet

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,
Alex

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.

Thanks,

Ranjeet