Guard against spurious wakeups in devicediscoveryclient.cpp
authorWilliam Dieter <william.r.dieter@intel.com>
Tue, 17 Feb 2015 05:41:32 +0000 (00:41 -0500)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Thu, 19 Feb 2015 03:38:11 +0000 (03:38 +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: I19b7ee13650b9b80250f935e2099119611fa61b3
Signed-off-by: William Dieter <william.r.dieter@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/355
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
resource/examples/devicediscoveryclient.cpp

index f08a8c7fca651b1e8521c018a68f126a8defe772..9352120b0e16df47e751f1562646d36003be3c44 100644 (file)
@@ -135,7 +135,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);
+        }
 
     }catch(OCException& e)
     {