diff options
author | Manjunath Kudlur <keveman@gmail.com> | 2015-11-06 16:27:58 -0800 |
---|---|---|
committer | Manjunath Kudlur <keveman@gmail.com> | 2015-11-06 16:27:58 -0800 |
commit | f41959ccb2d9d4c722fe8fc3351401d53bcf4900 (patch) | |
tree | ef0ca22cb2a5ac4bdec9d080d8e0788a53ed496d /tensorflow/core/lib/core/blocking_counter_test.cc |
TensorFlow: Initial commit of TensorFlow library.
TensorFlow is an open source software library for numerical computation
using data flow graphs.
Base CL: 107276108
Diffstat (limited to 'tensorflow/core/lib/core/blocking_counter_test.cc')
-rw-r--r-- | tensorflow/core/lib/core/blocking_counter_test.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tensorflow/core/lib/core/blocking_counter_test.cc b/tensorflow/core/lib/core/blocking_counter_test.cc new file mode 100644 index 0000000000..feb0342086 --- /dev/null +++ b/tensorflow/core/lib/core/blocking_counter_test.cc @@ -0,0 +1,36 @@ +#include <gtest/gtest.h> + +#include "tensorflow/core/lib/core/blocking_counter.h" +#include "tensorflow/core/lib/core/threadpool.h" + +namespace tensorflow { +namespace { + +TEST(BlockingCounterTest, TestZero) { + BlockingCounter bc(0); + bc.Wait(); +} + +TEST(BlockingCounterTest, TestSingleThread) { + BlockingCounter bc(2); + bc.DecrementCount(); + bc.DecrementCount(); + bc.Wait(); +} + +TEST(BlockingCounterTest, TestMultipleThread) { + int N = 3; + thread::ThreadPool* thread_pool = + new thread::ThreadPool(Env::Default(), "test", N); + + BlockingCounter bc(N); + for (int i = 0; i < N; ++i) { + thread_pool->Schedule([&bc] { bc.DecrementCount(); }); + } + + bc.Wait(); + delete thread_pool; +} + +} // namespace +} // namespace tensorflow |