Commit f6ece5d2 authored by Davis King's avatar Davis King

merged

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