Rip-Rip/clang_complete — pull request #153 by dave-h (2012-06-03 23:40:23+00:00)
Title: Crash when clang_periodic_quickfix enabled, race with WarmupCache

When opening a file that take a long time for clang to parse, I'm occasionally hitting asserts in libclang about concurrent access, and even sometimes an actual crash of vim.

Turns out if the initial parsing of the file when its opened, triggered by WarmupCache (in libclang.py), takes long enough, then if g:clang_periodic_quickfix is set, the periodic update of the quickfix window may be triggered before the initial parsing has finished.

Currently there's a lock preventing concurrent accesses when doing actual code completion, but not for updating the quickfix window. This replaces CompleteThread's lock with a global libclangLock that is also used by updateCurrentDiagnotics

Originally came across this only when using a debug build of clang, but I have since been able to reproduce on a normal build with large enough source files, e.g. the 400k clang/lib/Sema/SemaDecl.cpp from clang's own source code.