1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
|
// Copyright (C) 2008 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_THREAD_POOl_ABSTRACT_Hh_
#ifdef DLIB_THREAD_POOl_ABSTRACT_Hh_
#include "threads_kernel_abstract.h"
#include "../uintn.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
template <
typename T
>
class future
{
/*!
INITIAL VALUE
- is_ready() == true
WHAT THIS OBJECT REPRESENTS
This object represents a container that allows you to safely pass objects
into the tasks performed by the thread_pool object defined below. An
example will make it clear:
// Suppose you have a global function defined as follows
void add (int a, int b, int& result) { result = a + b; }
// Also suppose you have a thread_pool named tp defined somewhere.
// Then you could do the following.
future<int> a, b, result;
a = 3;
b = 4;
// this function call causes another thread to execute a call to the add() function
// and passes in the int objects contained in a, b, and result
tp.add_task(add,a,b,result);
// This line will wait for the task in the thread pool to finish and then print the
// value in the result integer. So it will print a 7.
cout << result << endl;
!*/
public:
future (
);
/*!
ensures
- The object of type T contained in this future has
an initial value for its type.
- #is_ready() == true
!*/
future (
const T& item
);
/*!
ensures
- #get() == item
- #is_ready() == true
!*/
future (
const future& item
);
/*!
ensures
- if (item.is_ready() == false) then
- the call to this function blocks until the thread processing the task related
to the item future has finished.
- #is_ready() == true
- #item.is_ready() == true
- #get() == item.get()
!*/
~future (
);
/*!
ensures
- if (is_ready() == false) then
- the call to this function blocks until the thread processing the task related
to this future has finished.
!*/
bool is_ready (
) const;
/*!
ensures
- if (the value of this future may not yet be ready to be accessed because it
is in use by a task in a thread_pool) then
- returns false
- else
- returns true
!*/
future& operator=(
const T& item
);
/*!
ensures
- if (is_ready() == false) then
- the call to this function blocks until the thread processing the task related
to this future has finished.
- #is_ready() == true
- #get() == item
- returns *this
!*/
future& operator=(
const future& item
);
/*!
ensures
- if (is_ready() == false || item.is_ready() == false) then
- the call to this function blocks until the threads processing the tasks related
to this future and the item future have finished.
- #is_ready() == true
- #item.is_ready() == true
- #get() == item.get()
- returns *this
!*/
operator T& (
);
/*!
ensures
- if (is_ready() == false) then
- the call to this function blocks until the thread processing the task related
to this future has finished.
- #is_ready() == true
- returns get()
!*/
operator const T& (
) const;
/*!
ensures
- if (is_ready() == false) then
- the call to this function blocks until the thread processing the task related
to this future has finished.
- #is_ready() == true
- returns get()
!*/
T& get (
);
/*!
ensures
- if (is_ready() == false) then
- the call to this function blocks until the thread processing the task related
to this future has finished.
- #is_ready() == true
- returns a non-const reference to the object of type T contained inside this future
!*/
const T& get (
) const;
/*!
ensures
- if (is_ready() == false) then
- the call to this function blocks until the thread processing the task related
to this future has finished.
- #is_ready() == true
- returns a const reference to the object of type T contained inside this future
!*/
};
// ----------------------------------------------------------------------------------------
template <typename T>
inline void swap (
future<T>& a,
future<T>& b
) { std::swap(a.get(), b.get()); }
/*!
provides a global swap function
!*/
// ----------------------------------------------------------------------------------------
// The future object comes with overloads for all the usual comparison operators.
template <typename T> bool operator== (const future<T>& a, const future<T>& b) { return a.get() == b.get(); }
template <typename T> bool operator!= (const future<T>& a, const future<T>& b) { return a.get() != b.get(); }
template <typename T> bool operator<= (const future<T>& a, const future<T>& b) { return a.get() <= b.get(); }
template <typename T> bool operator>= (const future<T>& a, const future<T>& b) { return a.get() >= b.get(); }
template <typename T> bool operator< (const future<T>& a, const future<T>& b) { return a.get() < b.get(); }
template <typename T> bool operator> (const future<T>& a, const future<T>& b) { return a.get() > b.get(); }
template <typename T> bool operator== (const future<T>& a, const T& b) { return a.get() == b; }
template <typename T> bool operator== (const T& a, const future<T>& b) { return a == b.get(); }
template <typename T> bool operator!= (const future<T>& a, const T& b) { return a.get() != b; }
template <typename T> bool operator!= (const T& a, const future<T>& b) { return a != b.get(); }
template <typename T> bool operator<= (const future<T>& a, const T& b) { return a.get() <= b; }
template <typename T> bool operator<= (const T& a, const future<T>& b) { return a <= b.get(); }
template <typename T> bool operator>= (const future<T>& a, const T& b) { return a.get() >= b; }
template <typename T> bool operator>= (const T& a, const future<T>& b) { return a >= b.get(); }
template <typename T> bool operator< (const future<T>& a, const T& b) { return a.get() < b; }
template <typename T> bool operator< (const T& a, const future<T>& b) { return a < b.get(); }
template <typename T> bool operator> (const future<T>& a, const T& b) { return a.get() > b; }
template <typename T> bool operator> (const T& a, const future<T>& b) { return a > b.get(); }
// ----------------------------------------------------------------------------------------
class thread_pool
{
/*!
WHAT THIS OBJECT REPRESENTS
This object represents a fixed size group of threads which you can
submit tasks to and then wait for those tasks to be completed.
Note that setting the number of threads to 0 is a valid way to
use this object. It causes it to not contain any threads
at all. When tasks are submitted to the object in this mode
the tasks are processed within the calling thread. So in this
mode any thread that calls add_task() is considered to be
a thread_pool thread capable of executing tasks.
This object is also implemented such that no memory allocations occur
after the thread_pool has been constructed so long as the user doesn't
call any of the add_task_by_value() routines. The future object also
doesn't perform any memory allocations or contain any system resources
such as mutex objects.
EXCEPTIONS
Note that if an exception is thrown inside a task thread and is not caught
then the exception will be trapped inside the thread pool and rethrown at a
later time when someone calls one of the add task or wait member functions
of the thread pool. This allows exceptions to propagate out of task threads
and into the calling code where they can be handled.
!*/
public:
explicit thread_pool (
unsigned long num_threads
);
/*!
ensures
- #num_threads_in_pool() == num_threads
throws
- std::bad_alloc
- dlib::thread_error
the constructor may throw this exception if there is a problem
gathering resources to create threading objects.
!*/
~thread_pool(
);
/*!
ensures
- blocks until all tasks in the pool have finished.
- If one of the threads has generated an exception but it hasn't yet been
rethrown to the caller (e.g. by calling wait_for_all_tasks()) then the
program will be terminated. So make sure you handle all the possible
exceptions from your tasks.
!*/
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 (
) const;
/*!
ensures
- returns the number of threads contained in this thread pool. That is, returns
the maximum number of tasks that this object will process concurrently.
!*/
template <typename F>
uint64 add_task_by_value (
const F& function_object
);
/*!
requires
- function_object() is a valid expression
ensures
- makes a copy of function_object, call it FCOPY.
- if (is_task_thread() == true and there aren't any free threads available) then
- calls FCOPY() within the calling thread and returns when it finishes
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls FCOPY().
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template <typename T>
uint64 add_task (
T& obj,
void (T::*funct)()
);
/*!
requires
- funct == a valid member function pointer for class T
- obj will not go out of scope until after the task has completed (i.e.
this function passes obj to the task by reference. If you want to avoid
this restriction then use add_task_by_value())
ensures
- if (is_task_thread() == true and there aren't any free threads available) then
- calls (obj.*funct)() within the calling thread and returns
when it finishes.
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls (obj.*funct)()
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template <typename T>
uint64 add_task_by_value (
const T& obj,
void (T::*funct)()
);
/*!
requires
- funct == a valid member function pointer for class T
ensures
- makes a copy of obj, call it OBJ_COPY.
- if (is_task_thread() == true and there aren't any free threads available) then
- calls (OBJ_COPY.*funct)() within the calling thread and returns
when it finishes.
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls (OBJ_COPY.*funct)().
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template <typename T>
uint64 add_task (
T& obj,
void (T::*funct)(long),
long arg1
);
/*!
requires
- funct == a valid member function pointer for class T
- obj will not go out of scope until after the task has completed (i.e.
this function passes obj to the task by reference. If you want to avoid
this restriction then use add_task_by_value())
ensures
- if (is_task_thread() == true and there aren't any free threads available) then
- calls (obj.*funct)(arg1) within the calling thread and returns
when it finishes
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls (obj.*funct)(arg1)
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template <typename T>
uint64 add_task (
T& obj,
void (T::*funct)(long,long),
long arg1,
long arg2
);
/*!
requires
- funct == a valid member function pointer for class T
- obj will not go out of scope until after the task has completed (i.e.
this function passes obj to the task by reference. If you want to avoid
this restriction then use add_task_by_value())
ensures
- if (is_task_thread() == true and there aren't any free threads available) then
- calls (obj.*funct)(arg1,arg2) within the calling thread and returns
when it finishes
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls (obj.*funct)(arg1,arg2)
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
void wait_for_task (
uint64 task_id
) const;
/*!
ensures
- if (there is currently a task with the given id being executed in the thread pool) then
- the call to this function blocks until the task with the given id is complete
- else
- the call to this function returns immediately
!*/
void wait_for_all_tasks (
) const;
/*!
ensures
- the call to this function blocks until all tasks which were submitted
to the thread pool by the thread that is calling this function have
finished.
!*/
// --------------------
template <typename F, typename A1>
uint64 add_task (
F& function_object,
future<A1>& arg1
);
/*!
requires
- 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)
- function_object will not go out of scope until after the task has completed (i.e.
this function passes function_object to the task by reference. If you want to avoid
this restriction then use add_task_by_value())
ensures
- if (is_task_thread() == true and there aren't any free threads available) then
- calls function_object(arg1.get()) within the calling thread and returns
when it finishes
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls function_object(arg1.get()).
- #arg1.is_ready() == false
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template <typename F, typename A1>
uint64 add_task_by_value (
const F& function_object,
future<A1>& arg1
);
/*!
requires
- 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)
ensures
- makes a copy of function_object, call it FCOPY.
- if (is_task_thread() == true and there aren't any free threads available) then
- calls FCOPY(arg1.get()) within the calling thread and returns when it finishes
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls FCOPY(arg1.get()).
- #arg1.is_ready() == false
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template <typename T, typename T1, typename A1>
uint64 add_task (
T& obj,
void (T::*funct)(T1),
future<A1>& arg1
);
/*!
requires
- funct == a valid member function pointer for class T
- (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)
- obj will not go out of scope until after the task has completed (i.e.
this function passes obj to the task by reference. If you want to avoid
this restriction then use add_task_by_value())
ensures
- if (is_task_thread() == true and there aren't any free threads available) then
- calls (obj.*funct)(arg1.get()) within the calling thread and returns
when it finishes
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls (obj.*funct)(arg1.get()).
- #arg1.is_ready() == false
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template <typename T, typename T1, typename A1>
uint64 add_task_by_value (
const T& obj,
void (T::*funct)(T1),
future<A1>& arg1
);
/*!
requires
- funct == a valid member function pointer for class T
- (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)
ensures
- makes a copy of obj, call it OBJ_COPY.
- if (is_task_thread() == true and there aren't any free threads available) then
- calls (OBJ_COPY.*funct)(arg1.get()) within the calling thread and returns
when it finishes.
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls (OBJ_COPY.*funct)(arg1.get()).
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template <typename T, typename T1, typename A1>
uint64 add_task (
const T& obj,
void (T::*funct)(T1) const,
future<A1>& arg1
);
/*!
requires
- funct == a valid member function pointer for class T
- (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)
- obj will not go out of scope until after the task has completed (i.e.
this function passes obj to the task by reference. If you want to avoid
this restriction then use add_task_by_value())
ensures
- if (is_task_thread() == true and there aren't any free threads available) then
- calls (obj.*funct)(arg1.get()) within the calling thread and returns
when it finishes
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls (obj.*funct)(arg1.get()).
- #arg1.is_ready() == false
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template <typename T, typename T1, typename A1>
uint64 add_task_by_value (
const T& obj,
void (T::*funct)(T1) const,
future<A1>& arg1
);
/*!
requires
- funct == a valid member function pointer for class T
- (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)
ensures
- makes a copy of obj, call it OBJ_COPY.
- if (is_task_thread() == true and there aren't any free threads available) then
- calls (OBJ_COPY.*funct)(arg1.get()) within the calling thread and returns
when it finishes.
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls (OBJ_COPY.*funct)(arg1.get()).
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
template <typename T1, typename A1>
uint64 add_task (
void (*funct)(T1),
future<A1>& arg1
);
/*!
requires
- funct == a valid function pointer
- (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)
ensures
- if (is_task_thread() == true and there aren't any free threads available) then
- calls funct(arg1.get()) within the calling thread and returns
when it finishes
- else
- the call to this function blocks until there is a free thread in the pool
to process this new task. Once a free thread is available the task
is handed off to that thread which then calls funct(arg1.get()).
- #arg1.is_ready() == false
- returns a task id that can be used by this->wait_for_task() to wait
for the submitted task to finish.
!*/
// --------------------------------------------------------------------------------
// The remainder of this class just contains overloads for add_task() and add_task_by_value()
// that take up to 4 futures (as well as 0 futures). Their behavior is identical to the above
// add_task() and add_task_by_value() functions.
// --------------------------------------------------------------------------------
template <typename F, typename A1, typename A2>
uint64 add_task (
F& function_object,
future<A1>& arg1,
future<A2>& arg2
);
template <typename F, typename A1, typename A2>
uint64 add_task_by_value (
const F& function_object,
future<A1>& arg1,
future<A2>& arg2
);
template <typename T, typename T1, typename A1,
typename T2, typename A2>
uint64 add_task (
T& obj,
void (T::*funct)(T1,T2),
future<A1>& arg1,
future<A2>& arg2
);
uint64 add_task_by_value (
const T& obj,
void (T::*funct)(T1,T2),
future<A1>& arg1,
future<A2>& arg2
);
template <typename T, typename T1, typename A1,
typename T2, typename A2>
uint64 add_task (
const T& obj,
void (T::*funct)(T1,T2) const,
future<A1>& arg1,
future<A2>& arg2
);
template <typename T, typename T1, typename A1,
typename T2, typename A2>
uint64 add_task_by_value (
const T& obj,
void (T::*funct)(T1,T2) const,
future<A1>& arg1,
future<A2>& arg2
);
template <typename T1, typename A1,
typename T2, typename A2>
uint64 add_task (
void (*funct)(T1,T2),
future<A1>& arg1,
future<A2>& arg2
);
// --------------------
template <typename F, typename A1, typename A2, typename A3>
uint64 add_task (
F& function_object,
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3
);
template <typename F, typename A1, typename A2, typename A3>
uint64 add_task_by_value (
const F& function_object,
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3
);
template <typename T, typename T1, typename A1,
typename T2, typename A2,
typename T3, typename A3>
uint64 add_task (
T& obj,
void (T::*funct)(T1,T2,T3),
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3
);
template <typename T, typename T1, typename A1,
typename T2, typename A2,
typename T3, typename A3>
uint64 add_task_by_value (
const T& obj,
void (T::*funct)(T1,T2,T3),
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3
);
template <typename T, typename T1, typename A1,
typename T2, typename A2,
typename T3, typename A3>
uint64 add_task (
const T& obj,
void (T::*funct)(T1,T2,T3) const,
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3
);
template <typename T, typename T1, typename A1,
typename T2, typename A2,
typename T3, typename A3>
uint64 add_task_by_value (
const T& obj,
void (T::*funct)(T1,T2,T3) const,
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3
);
template <typename T1, typename A1,
typename T2, typename A2,
typename T3, typename A3>
uint64 add_task (
void (*funct)(T1,T2,T3),
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3
);
// --------------------
template <typename F, typename A1, typename A2, typename A3, typename A4>
uint64 add_task (
F& function_object,
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3,
future<A4>& arg4
);
template <typename F, typename A1, typename A2, typename A3, typename A4>
uint64 add_task_by_value (
const F& function_object,
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3,
future<A4>& arg4
);
template <typename T, typename T1, typename A1,
typename T2, typename A2,
typename T3, typename A3,
typename T4, typename A4>
uint64 add_task (
T& obj,
void (T::*funct)(T1,T2,T3,T4),
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3,
future<A4>& arg4
);
template <typename T, typename T1, typename A1,
typename T2, typename A2,
typename T3, typename A3,
typename T4, typename A4>
uint64 add_task_by_value (
const T& obj,
void (T::*funct)(T1,T2,T3,T4),
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3,
future<A4>& arg4
);
template <typename T, typename T1, typename A1,
typename T2, typename A2,
typename T3, typename A3,
typename T4, typename A4>
uint64 add_task (
const T& obj,
void (T::*funct)(T1,T2,T3,T4) const,
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3,
future<A4>& arg4
);
template <typename T, typename T1, typename A1,
typename T2, typename A2,
typename T3, typename A3,
typename T4, typename A4>
uint64 add_task_by_value (
const T& obj,
void (T::*funct)(T1,T2,T3,T4) const,
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3,
future<A4>& arg4
);
template <typename T1, typename A1,
typename T2, typename A2,
typename T3, typename A3,
typename T4, typename A4>
uint64 add_task (
void (*funct)(T1,T2,T3,T4),
future<A1>& arg1,
future<A2>& arg2,
future<A3>& arg3,
future<A4>& arg4
);
// --------------------
template <typename F>
uint64 add_task (
F& function_object
);
template <typename T>
uint64 add_task (
const T& obj,
void (T::*funct)() const,
);
template <typename T>
uint64 add_task_by_value (
const T& obj,
void (T::*funct)() const
);
uint64 add_task (
void (*funct)()
);
// --------------------
private:
// restricted functions
thread_pool(thread_pool&); // copy constructor
thread_pool& operator=(thread_pool&); // assignment operator
};
}
// ----------------------------------------------------------------------------------------
#endif // DLIB_THREAD_POOl_ABSTRACT_Hh_
|