Commit f6ece5d2 authored by Davis King's avatar Davis King

merged

parents bdbf7bb8 4dfeb7e1
...@@ -615,7 +615,7 @@ namespace dlib ...@@ -615,7 +615,7 @@ namespace dlib
alias_tensor_instance operator() ( alias_tensor_instance operator() (
tensor& t, tensor& t,
size_t offset size_t offset
) ) const
{ {
DLIB_CASSERT(offset+size() <= t.size()); DLIB_CASSERT(offset+size() <= t.size());
...@@ -637,7 +637,7 @@ namespace dlib ...@@ -637,7 +637,7 @@ namespace dlib
alias_tensor_const_instance operator() ( alias_tensor_const_instance operator() (
const tensor& t, const tensor& t,
size_t offset size_t offset
) ) const
{ {
alias_tensor_const_instance temp; alias_tensor_const_instance temp;
temp.inst = (*this)(const_cast<tensor&>(t),offset); temp.inst = (*this)(const_cast<tensor&>(t),offset);
...@@ -645,7 +645,7 @@ namespace dlib ...@@ -645,7 +645,7 @@ namespace dlib
} }
private: private:
alias_tensor_instance inst; mutable alias_tensor_instance inst;
}; };
inline void serialize(const alias_tensor& item, std::ostream& out) inline void serialize(const alias_tensor& item, std::ostream& out)
......
...@@ -663,7 +663,7 @@ namespace dlib ...@@ -663,7 +663,7 @@ namespace dlib
alias_tensor_instance operator() ( alias_tensor_instance operator() (
tensor& t, tensor& t,
size_t offset size_t offset
); ) const;
/*! /*!
requires requires
- offset+size() <= t.size() - offset+size() <= t.size()
...@@ -684,7 +684,7 @@ namespace dlib ...@@ -684,7 +684,7 @@ namespace dlib
alias_tensor_const_instance operator() ( alias_tensor_const_instance operator() (
const tensor& t, const tensor& t,
size_t offset size_t offset
); ) const;
/*! /*!
requires requires
- offset+size() <= t.size() - offset+size() <= t.size()
......
...@@ -1812,13 +1812,9 @@ namespace dlib ...@@ -1812,13 +1812,9 @@ namespace dlib
) )
{ {
// assign the given value to every spot in this matrix // assign the given value to every spot in this matrix
for (long r = 0; r < nr(); ++r) const long size = nr()*nc();
{ for (long i = 0; i < size; ++i)
for (long c = 0; c < nc(); ++c) data(i) = val;
{
data(r,c) = val;
}
}
// Now return the literal_assign_helper so that the user // Now return the literal_assign_helper so that the user
// can use the overloaded comma notation to initialize // can use the overloaded comma notation to initialize
......
...@@ -19,12 +19,11 @@ namespace dlib ...@@ -19,12 +19,11 @@ namespace dlib
we_are_destructing(false) we_are_destructing(false)
{ {
tasks.resize(num_threads); tasks.resize(num_threads);
threads.resize(num_threads);
for (unsigned long i = 0; i < num_threads; ++i) for (unsigned long i = 0; i < num_threads; ++i)
{ {
register_thread(*this, &thread_pool_implementation::thread); threads[i] = std::thread([&](){this->thread();});
} }
start();
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -60,7 +59,10 @@ namespace dlib ...@@ -60,7 +59,10 @@ namespace dlib
task_ready_signaler.broadcast(); task_ready_signaler.broadcast();
} }
wait(); // wait for all threads to terminate
for (auto& t : threads)
t.join();
threads.clear();
// Throw any unhandled exceptions. Since shutdown_pool() is only called in the // Throw any unhandled exceptions. Since shutdown_pool() is only called in the
// destructor this will kill the program. // destructor this will kill the program.
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "../smart_pointers_thread_safe.h" #include "../smart_pointers_thread_safe.h"
#include "../smart_pointers.h" #include "../smart_pointers.h"
#include <exception> #include <exception>
#include <thread>
namespace dlib namespace dlib
{ {
...@@ -126,7 +127,7 @@ namespace dlib ...@@ -126,7 +127,7 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
class thread_pool_implementation : private multithreaded_object class thread_pool_implementation
{ {
/*! /*!
CONVENTION CONVENTION
...@@ -474,6 +475,8 @@ namespace dlib ...@@ -474,6 +475,8 @@ namespace dlib
signaler task_ready_signaler; signaler task_ready_signaler;
bool we_are_destructing; bool we_are_destructing;
std::vector<std::thread> threads;
// restricted functions // restricted functions
thread_pool_implementation(thread_pool_implementation&); // copy constructor thread_pool_implementation(thread_pool_implementation&); // copy constructor
thread_pool_implementation& operator=(thread_pool_implementation&); // assignment operator thread_pool_implementation& operator=(thread_pool_implementation&); // assignment operator
......
...@@ -39,15 +39,6 @@ namespace dlib ...@@ -39,15 +39,6 @@ namespace dlib
bool thread_pool_has_been_destroyed = false; bool thread_pool_has_been_destroyed = false;
// ----------------------------------------------------------------------------------------
threader& thread_pool (
)
{
static threader* thread_pool = new threader;
return *thread_pool;
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
struct threader_destruct_helper struct threader_destruct_helper
...@@ -59,7 +50,16 @@ namespace dlib ...@@ -59,7 +50,16 @@ namespace dlib
thread_pool().destruct_if_ready(); thread_pool().destruct_if_ready();
} }
}; };
static threader_destruct_helper a;
// ----------------------------------------------------------------------------------------
threader& thread_pool (
)
{
static threader* thread_pool = new threader;
static threader_destruct_helper a;
return *thread_pool;
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
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