37 #include <gtest/gtest.h> 39 #include <boost/thread.hpp> 40 #include <boost/bind.hpp> 48 : done_protecting_(false)
58 EXPECT_TRUE(protector_2.isProtected());
62 boost::mutex::scoped_lock lock(mutex_);
63 done_protecting_ =
true;
69 printf(
"protecting thread is sleeping\n");
70 boost::this_thread::sleep(boost::posix_time::microseconds(5000000));
71 printf(
"protecting thread is exiting\n");
87 boost::mutex::scoped_lock lock(mutex_);
88 while (!done_protecting_) {
89 cond_.timed_wait(lock, boost::posix_time::milliseconds(100));
93 printf(
"About to destruct\n");
95 printf(
"Done destructing\n");
113 EXPECT_TRUE(protector_2.isProtected());
125 int main(
int argc,
char ** argv)
127 testing::InitGoogleTest(&argc, argv);
130 return RUN_ALL_TESTS();
bool isProtected()
Checks if the ScopedProtector successfully protected the DestructionGuard.
TEST(DestructionGuard, easy_test)
This class protects an object from being destructed until all users of that object relinquish control...
int main(int argc, char **argv)
Protects a DestructionGuard until this object goes out of scope.
TEST_F(TestRunner, threaded_test)