Commit 13cd7606 authored by Davis King's avatar Davis King

Clarified the spec for the thread_pool.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402682
parent e1809547
...@@ -267,6 +267,16 @@ namespace dlib ...@@ -267,6 +267,16 @@ namespace dlib
return tasks[idx].task_id; return tasks[idx].task_id;
} }
// ----------------------------------------------------------------------------------------
bool thread_pool::
is_task_thread (
) const
{
auto_mutex M(m);
return is_worker_thread(get_thread_id());
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -130,6 +130,8 @@ namespace dlib ...@@ -130,6 +130,8 @@ namespace dlib
- else - else
- we_are_destructing == false - we_are_destructing == false
- is_task_thread() == is_worker_thread(get_thread_id())
- m == the mutex used to protect everything in this object - m == the mutex used to protect everything in this object
- worker_thread_ids == an array that contains the thread ids for - worker_thread_ids == an array that contains the thread ids for
all the threads in the thread pool all the threads in the thread pool
...@@ -154,6 +156,9 @@ namespace dlib ...@@ -154,6 +156,9 @@ namespace dlib
void wait_for_all_tasks ( void wait_for_all_tasks (
) const; ) const;
bool is_task_thread (
) const;
template <typename T> template <typename T>
uint64 add_task ( uint64 add_task (
T& obj, T& obj,
......
...@@ -236,6 +236,17 @@ namespace dlib ...@@ -236,6 +236,17 @@ namespace dlib
- all resources allocated by *this have been freed. - all resources allocated by *this have been freed.
!*/ !*/
bool is_task_thread (
) const;
/*!
ensures
- if (the thread calling this function is one of the threads in this
thread pool or num_threads_in_pool() == 0) then
- returns true
- else
- returns false
!*/
unsigned long num_threads_in_pool ( unsigned long num_threads_in_pool (
) const; ) const;
/*! /*!
...@@ -253,8 +264,7 @@ namespace dlib ...@@ -253,8 +264,7 @@ namespace dlib
requires requires
- funct == a valid member function pointer for class T - funct == a valid member function pointer for class T
ensures ensures
- if (the thread calling this function is actually one of the threads in the - if (is_task_thread() == true and there aren't any free threads available) then
thread pool and there aren't any free threads available) then
- calls (obj.*funct)() within the calling thread and returns - calls (obj.*funct)() within the calling thread and returns
when it finishes when it finishes
- else - else
...@@ -275,8 +285,7 @@ namespace dlib ...@@ -275,8 +285,7 @@ namespace dlib
requires requires
- funct == a valid member function pointer for class T - funct == a valid member function pointer for class T
ensures ensures
- if (the thread calling this function is actually one of the threads in the - if (is_task_thread() == true and there aren't any free threads available) then
thread pool and there aren't any free threads available) then
- calls (obj.*funct)(arg1) within the calling thread and returns - calls (obj.*funct)(arg1) within the calling thread and returns
when it finishes when it finishes
- else - else
...@@ -298,8 +307,7 @@ namespace dlib ...@@ -298,8 +307,7 @@ namespace dlib
requires requires
- funct == a valid member function pointer for class T - funct == a valid member function pointer for class T
ensures ensures
- if (the thread calling this function is actually one of the threads in the - if (is_task_thread() == true and there aren't any free threads available) then
thread pool and there aren't any free threads available) then
- calls (obj.*funct)(arg1,arg2) within the calling thread and returns - calls (obj.*funct)(arg1,arg2) within the calling thread and returns
when it finishes when it finishes
- else - else
...@@ -342,8 +350,7 @@ namespace dlib ...@@ -342,8 +350,7 @@ namespace dlib
- function_object(arg1.get()) is a valid expression - function_object(arg1.get()) is a valid expression
(i.e. The A1 type stored in the future must be a type that can be passed into the given function object) (i.e. The A1 type stored in the future must be a type that can be passed into the given function object)
ensures ensures
- if (the thread calling this function is actually one of the threads in the - if (is_task_thread() == true and there aren't any free threads available) then
thread pool and there aren't any free threads available) then
- calls function_object(arg1.get()) within the calling thread and returns - calls function_object(arg1.get()) within the calling thread and returns
when it finishes when it finishes
- else - else
...@@ -367,8 +374,7 @@ namespace dlib ...@@ -367,8 +374,7 @@ namespace dlib
- (obj.*funct)(arg1.get()) must be a valid expression. - (obj.*funct)(arg1.get()) must be a valid expression.
(i.e. The A1 type stored in the future must be a type that can be passed into the given function) (i.e. The A1 type stored in the future must be a type that can be passed into the given function)
ensures ensures
- if (the thread calling this function is actually one of the threads in the - if (is_task_thread() == true and there aren't any free threads available) then
thread pool and there aren't any free threads available) then
- calls (obj.*funct)(arg1.get()) within the calling thread and returns - calls (obj.*funct)(arg1.get()) within the calling thread and returns
when it finishes when it finishes
- else - else
...@@ -392,8 +398,7 @@ namespace dlib ...@@ -392,8 +398,7 @@ namespace dlib
- (obj.*funct)(arg1.get()) must be a valid expression. - (obj.*funct)(arg1.get()) must be a valid expression.
(i.e. The A1 type stored in the future must be a type that can be passed into the given function) (i.e. The A1 type stored in the future must be a type that can be passed into the given function)
ensures ensures
- if (the thread calling this function is actually one of the threads in the - if (is_task_thread() == true and there aren't any free threads available) then
thread pool and there aren't any free threads available) then
- calls (obj.*funct)(arg1.get()) within the calling thread and returns - calls (obj.*funct)(arg1.get()) within the calling thread and returns
when it finishes when it finishes
- else - else
...@@ -416,8 +421,7 @@ namespace dlib ...@@ -416,8 +421,7 @@ namespace dlib
- (funct)(arg1.get()) must be a valid expression. - (funct)(arg1.get()) must be a valid expression.
(i.e. The A1 type stored in the future must be a type that can be passed into the given function) (i.e. The A1 type stored in the future must be a type that can be passed into the given function)
ensures ensures
- if (the thread calling this function is actually one of the threads in the - if (is_task_thread() == true and there aren't any free threads available) then
thread pool and there aren't any free threads available) then
- calls funct(arg1.get()) within the calling thread and returns - calls funct(arg1.get()) within the calling thread and returns
when it finishes when it finishes
- else - else
......
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