Commit e1809547 authored by Davis King's avatar Davis King

Added some more tests for the thread_pool object.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402681
parent bbf90ce0
...@@ -25,6 +25,16 @@ namespace ...@@ -25,6 +25,16 @@ namespace
float val; float val;
}; };
struct add_functor
{
template <typename T, typename U, typename V>
void operator()(T a, U b, V& res)
{
dlib::sleep(20);
res = a + b;
}
};
void gset_struct_to_zero (some_struct& a) { a.val = 0; } void gset_struct_to_zero (some_struct& a) { a.val = 0; }
void gset_to_zero (int& a) { a = 0; } void gset_to_zero (int& a) { a = 0; }
void gincrement (int& a) { ++a; } void gincrement (int& a) { ++a; }
...@@ -44,7 +54,9 @@ namespace ...@@ -44,7 +54,9 @@ namespace
void perform_test ( void perform_test (
) )
{ {
thread_pool tp(3); for (int num_threads= 0; num_threads < 4; ++num_threads)
{
thread_pool tp(num_threads);
print_spinner(); print_spinner();
future<int> a, b, c, res; future<int> a, b, c, res;
...@@ -176,6 +188,16 @@ namespace ...@@ -176,6 +188,16 @@ namespace
DLIB_CASSERT(obj.get().val == 8,""); DLIB_CASSERT(obj.get().val == 8,"");
tp.add_task(*this,&thread_pool_tester::set_struct_to_zero, obj); tp.add_task(*this,&thread_pool_tester::set_struct_to_zero, obj);
DLIB_CASSERT(obj.get().val == 0,""); DLIB_CASSERT(obj.get().val == 0,"");
a = 1;
b = 2;
res = 0;
add_functor f;
tp.add_task(f, a, b, res);
DLIB_CASSERT(a == 1,"");
DLIB_CASSERT(b == 2,"");
DLIB_CASSERT(res == 3,"");
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment