29 #include <boost/thread/thread.hpp> 30 #include <boost/bind.hpp> 31 #include <gtest/gtest.h> 43 boost::thread_group tg;
46 for (
int i = 0; i < num_threads; ++i)
51 boost::this_thread::sleep(boost::posix_time::seconds(2));
65 boost::this_thread::sleep(boost::posix_time::microseconds(1));
79 boost::this_thread::sleep(boost::posix_time::microseconds(1));
85 boost::shared_mutex
mut;
88 TEST(ThreadSafeMapOneThread, initialization)
95 int value = map.
find(
"a");
98 value = map.
find(
"b");
101 EXPECT_EQ(map.
keys().size(), 2);
103 EXPECT_STREQ(std::string(
"a").c_str(), std::string(map.
keys()[0]).c_str());
104 EXPECT_STREQ(std::string(
"b").c_str(), std::string(map.
keys()[1]).c_str());
107 TEST(ThreadSafeMapOneThread, update)
114 int value = map.
find(
"a");
117 value = map.
find(
"b");
122 value = map.
find(
"a");
125 value = map.
find(
"b");
129 TEST(ThreadSafeMapMultiThreads, update)
135 int main(
int argc,
char **argv)
137 testing::InitGoogleTest(&argc, argv);
138 return RUN_ALL_TESTS();
bool update(const std::string &first, const T &value)
We needed a threadsafe hash map, with the possibility of multiple readers accessing the map at the sa...
TestMultiThread(int num_threads)
int main(int argc, char **argv)
std::vector< std::string > keys()
T find(std::string first)
bool insert(const std::string &first, const T &value)
TEST(ThreadSafeMapOneThread, initialization)
threadsafe::Map< int > map_