aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/ModuleMap.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2013-05-08 23:29:24 +0000
committerRui Ueyama <ruiu@google.com>2013-05-08 23:29:24 +0000
commit980e52d7aece79c69cf176fb835c5ff5347f7a7b (patch)
treec56b37da65f6f206f66b95b2bee0b259329e5386 /clang/lib/Lex/ModuleMap.cpp
parentec504cfffdfbeaf17e492dbd5e38922afe4690bf (diff)
downloadllvm-980e52d7aece79c69cf176fb835c5ff5347f7a7b.zip
llvm-980e52d7aece79c69cf176fb835c5ff5347f7a7b.tar.gz
llvm-980e52d7aece79c69cf176fb835c5ff5347f7a7b.tar.bz2
[lld][Core] Fix latch synchronization bug.
We need to acquire a lock before signal a condition. Otherwise threads waiting on a condition variable can miss a signal. Consider two threads: Thread A executing dec() and thread B executing sync(). The initial value of _count is 1. If these two threads are interleaved in the following order, thread B misses the signal sent by thread A, because at the time thread A sends a signal, B is not waiting for it. Thread A | Thread B | std::unique_lock<std::mutex> lock(_condMut); | while (!(_count == 0)) { if (--_count == 0) | _cond_notify_all() | | _cond.wait(); | } Note that "wait(lock, pred)" is equivalent to "while(!pred()) wait(lock)", so I expanded it in the above example. Reviewers: Bigcheese CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D764 llvm-svn: 181484
Diffstat (limited to 'clang/lib/Lex/ModuleMap.cpp')
0 files changed, 0 insertions, 0 deletions