15 #include <boost/thread.hpp>
16 #include <boost/thread/mutex.hpp>
17 #include <glog/logging.h>
18 #include <gtest/gtest.h>
34 void Count(
int thread_id,
const int& i) {
39 TEST(ThreadPoolTest, BasicTest) {
40 const int OFFERED_RANGE = 10000;
46 for (
int i = 0; i <= OFFERED_RANGE; ++i) {
47 ASSERT_TRUE(thread_pool.
Offer(i));
53 ASSERT_FALSE(thread_pool.
Offer(-1));
56 int expected_count = (OFFERED_RANGE * (OFFERED_RANGE + 1)) / 2;
61 count += thread_counters[i];
64 EXPECT_EQ(expected_count, count);
69 int main(
int argc,
char** argv) {
72 ::testing::InitGoogleTest(&argc, argv);
73 return RUN_ALL_TESTS();
void Count(int thread_id, const int &i)
mutex thread_mutexes[NUM_THREADS]
int thread_counters[NUM_THREADS]
bool Offer(const T &work)
void InitGoogleLoggingSafe(const char *arg)
void InitThreading()
Initialises the threading subsystem. Must be called before a Thread is created.
uint32_t GetQueueSize() const
int main(int argc, char **argv)