From ac1fa8b79c738220bdd3fef27de99faf4a92fb78 Mon Sep 17 00:00:00 2001 From: William Dieter Date: Tue, 17 Feb 2015 00:41:32 -0500 Subject: [PATCH] Guard against spurious wakeups in devicediscoveryclient.cpp Like most condition variable implementations, std::condition_variable may wake up spuriously, even though it is not signalled (see http://en.cppreference.com/w/cpp/thread/condition_variable/wait). Since the intention of blocking on the std::condition_variable in main is to wait forever, add a loop to block again after spurious wakeups. Change-Id: I19b7ee13650b9b80250f935e2099119611fa61b3 Signed-off-by: William Dieter Reviewed-on: https://gerrit.iotivity.org/gerrit/355 Tested-by: jenkins-iotivity Reviewed-by: Sudarshan Prasad (cherry picked from commit 73b122b0590bc350c1a451d7d05db86e3f0121d3) Reviewed-on: https://gerrit.iotivity.org/gerrit/392 --- resource/examples/devicediscoveryclient.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/resource/examples/devicediscoveryclient.cpp b/resource/examples/devicediscoveryclient.cpp index fa630e3..8bbb55f 100644 --- a/resource/examples/devicediscoveryclient.cpp +++ b/resource/examples/devicediscoveryclient.cpp @@ -183,7 +183,10 @@ int main(int argc, char* argv[]) { std::mutex blocker; std::condition_variable cv; std::unique_lock lock(blocker); - cv.wait(lock); + while(true) + { + cv.wait(lock); + } }catch(OCException& e) { -- 2.7.4