Guard against spurious wakeups in devicediscoveryserver.cpp
authorWilliam Dieter <william.r.dieter@intel.com>
Tue, 17 Feb 2015 06:45:00 +0000 (01:45 -0500)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Sat, 21 Feb 2015 02:05:42 +0000 (02:05 +0000)
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: I97e89a1ec95d6ba65eeb7daff861ee0a65d03a7e
Signed-off-by: William Dieter <william.r.dieter@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/357
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
(cherry picked from commit 5df6036cde74bf174d9d61b618d81f8d7034d6c4)
Reviewed-on: https://gerrit.iotivity.org/gerrit/391

resource/examples/devicediscoveryserver.cpp

index 9db7736..26401ba 100644 (file)
@@ -157,7 +157,10 @@ int main()
     std::mutex blocker;
     std::condition_variable cv;
     std::unique_lock<std::mutex> lock(blocker);
-    cv.wait(lock);
+    while(true)
+    {
+        cv.wait(lock);
+    }
 
     // No explicit call to stop the platform.
     // When OCPlatform::destructor is invoked, internally we do platform cleanup