| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Functions | Variables
compile_all.cpp File Reference

threadpool tutorial. More...

`#include <boost/bind.hpp>`
`#include <boost/thread/mutex.hpp>`
`#include <iostream>`
`#include <sstream>`
`#include <boost/threadpool.hpp>`
Include dependency graph for compile_all.cpp:

Go to the source code of this file.

## Functions
void | print (string text)
template<typename T >
string | to_string (T const &value)
void | task_1 ()
void | task_2 ()
void | task_3 ()
int | task_4 ()
void | task_with_parameter (int value)
bool | looped_task ()
int | task_int ()
void | fifo_pool_test ()
void | lifo_pool_test ()
void | prio_pool_test ()
void | future_test ()
int | main (int, char *const [])

## Variables
boost::mutex | m_io_monitor
int | loops = 0

## Detailed Description

threadpool tutorial.

This file contains a tutorial for the threadpool library.

Copyright (c) 2005-2006 Philipp Henkel

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

http://threadpool.sourceforge.net

Definition in file compile_all.cpp.

## Function Documentation

void fifo_pool_test | ( |  | ) |

Definition at line 74 of file compile_all.cpp.

75 {
76 pool tp;
77
78 tp.schedule( &task_1 );
79 tp.schedule( boost::bind( task_with_parameter, 4 ) );
80
81 if ( !tp.empty() ) {
82 tp.clear(); // remove all tasks -> no output in this test
83 }
84
85 size_t active_threads = tp.active();
86 size_t pending_threads = tp.pending();
87 size_t total_threads = tp.size();
88
89 size_t dummy = active_threads + pending_threads + total_threads;
90 dummy++;
91
92 tp.size_controller().resize( 5 );
93 tp.wait();
94 }
boost::threadpool::thread_pool::wait
void wait(size_t task_threshold=0) const
The current thread of execution is blocked until the sum of all active and pending tasks is equal or ...
Definition: pool.hpp:176
task_with_parameter
void task_with_parameter(int value)
Definition: compile_all.cpp:59
boost::threadpool::thread_pool::schedule
bool schedule(task_type const &task)
Schedules a task for asynchronous execution.
Definition: pool.hpp:130
boost::threadpool::thread_pool::empty
bool empty() const
Indicates that there are no tasks pending.
Definition: pool.hpp:166
boost::threadpool::thread_pool::pending
size_t pending() const
Returns the number of tasks which are ready for execution.
Definition: pool.hpp:148
pool
Definition: PoolClasses.h:11
compareRootHistos.tp
tuple tp
Definition: compareRootHistos.py:417
boost::threadpool::thread_pool::active
size_t active() const
Returns the number of tasks which are currently executed.
Definition: pool.hpp:139
boost::threadpool::thread_pool::size_controller
size_controller_type size_controller()
Gets the size controller which manages the number of threads in the pool.
Definition: pool.hpp:111
task_1
void task_1()
Definition: compile_all.cpp:47
boost::threadpool::thread_pool::clear
void clear()
Removes all pending tasks from the pool&#39;s scheduler.
Definition: pool.hpp:156
boost::threadpool::thread_pool::size
size_t size() const
Gets the number of threads in the pool.
Definition: pool.hpp:120

void future_test | ( |  | ) |

Definition at line 112 of file compile_all.cpp.

113 {
114 fifo_pool tp( 5 );
115 future<int> fut = schedule( tp, &task_4 );
116 int res = fut();
117 }
std::future
task_4
int task_4()
Definition: compile_all.cpp:53
boost::threadpool::schedule
disable_if< is_void< typename result_of< Function() >::type >, future< typename result_of< Function() >::type >>::type schedule(Pool &pool, const Function &task)
Definition: future.hpp:111
compareRootHistos.tp
tuple tp
Definition: compareRootHistos.py:417
boost::threadpool::thread_pool
Thread pool.
Definition: pool.hpp:73

void lifo_pool_test | ( |  | ) |

Definition at line 96 of file compile_all.cpp.

97 {
98 lifo_pool tp;
99 tp.size_controller().resize( 0 );
100 schedule( tp, &task_1 );
101 tp.size_controller().resize( 10 );
102 tp.wait();
103 }
boost::threadpool::thread_pool::wait
void wait(size_t task_threshold=0) const
The current thread of execution is blocked until the sum of all active and pending tasks is equal or ...
Definition: pool.hpp:176
boost::threadpool::schedule
disable_if< is_void< typename result_of< Function() >::type >, future< typename result_of< Function() >::type >>::type schedule(Pool &pool, const Function &task)
Definition: future.hpp:111
compareRootHistos.tp
tuple tp
Definition: compareRootHistos.py:417
boost::threadpool::thread_pool::size_controller
size_controller_type size_controller()
Gets the size controller which manages the number of threads in the pool.
Definition: pool.hpp:111
task_1
void task_1()
Definition: compile_all.cpp:47
boost::threadpool::thread_pool
Thread pool.
Definition: pool.hpp:73

bool looped_task | ( |  | ) |

Definition at line 62 of file compile_all.cpp.

63 {
64 print( " looped_task()\n" );
65 return ++loops < 5;
66 }
loops
int loops
Definition: compile_all.cpp:61
print
void print(string text)
Definition: compile_all.cpp:30

int main | ( | int | ,
|  | char * | const[]
| ) |  |

Definition at line 119 of file compile_all.cpp.

120 {
121 fifo_pool_test();
122 lifo_pool_test();
123 prio_pool_test();
124 future_test();
125 return 0;
126 }
lifo_pool_test
void lifo_pool_test()
Definition: compile_all.cpp:96
future_test
void future_test()
Definition: compile_all.cpp:112
prio_pool_test
void prio_pool_test()
Definition: compile_all.cpp:105
fifo_pool_test
void fifo_pool_test()
Definition: compile_all.cpp:74

void print | ( | string | text | ) |

Definition at line 30 of file compile_all.cpp.

31 {
32 boost::mutex::scoped_lock lock( m_io_monitor );
33 cout << text;
34 }
std::lock
T lock(T...args)
m_io_monitor
boost::mutex m_io_monitor
Definition: compile_all.cpp:28
std::cout

void prio_pool_test | ( |  | ) |

Definition at line 105 of file compile_all.cpp.

106 {
107 prio_pool tp( 2 );
108 schedule( tp, prio_task_func( 1, &task_1 ) );
109 schedule( tp, prio_task_func( 10, &task_2 ) );
110 }
boost::threadpool::schedule
disable_if< is_void< typename result_of< Function() >::type >, future< typename result_of< Function() >::type >>::type schedule(Pool &pool, const Function &task)
Definition: future.hpp:111
compareRootHistos.tp
tuple tp
Definition: compareRootHistos.py:417
task_1
void task_1()
Definition: compile_all.cpp:47
boost::threadpool::thread_pool
Thread pool.
Definition: pool.hpp:73
task_2
void task_2()
Definition: compile_all.cpp:49
boost::threadpool::prio_task_func
Prioritized task function object.
Definition: task_adaptors.hpp:51

void task_1 | ( |  | ) |

Definition at line 47 of file compile_all.cpp.

47 { print( " task_1()\n" ); }
print
void print(string text)
Definition: compile_all.cpp:30

void task_2 | ( |  | ) |

Definition at line 49 of file compile_all.cpp.

49 { print( " task_2()\n" ); }
print
void print(string text)
Definition: compile_all.cpp:30

void task_3 | ( |  | ) |

Definition at line 51 of file compile_all.cpp.

51 { print( " task_3()\n" ); }
print
void print(string text)
Definition: compile_all.cpp:30

int task_4 | ( |  | ) |

Definition at line 53 of file compile_all.cpp.

54 {
55 print( " task_4()\n" );
56 return 4;
57 }
print
void print(string text)
Definition: compile_all.cpp:30

int task_int | ( |  | ) |

Definition at line 68 of file compile_all.cpp.

69 {
70 print( " task_int()\n" );
71 return 23;
72 }
print
void print(string text)
Definition: compile_all.cpp:30

void task_with_parameter | ( | int | value | ) |

Definition at line 59 of file compile_all.cpp.

59 { print( " task_with_parameter(" + to_string( value ) + ")\n" ); }
print
void print(string text)
Definition: compile_all.cpp:30
to_string
string to_string(T const &value)
Definition: compile_all.cpp:37
template<typename T >

string to_string | ( | T const & | value | ) |

Definition at line 37 of file compile_all.cpp.

38 {
39 ostringstream ost;
40 ost << value;
41 ost.flush();
42 return ost.str();
43 }
std::ostringstream
STL class.
std::ostringstream::str
T str(T...args)
std::ostringstream::flush
T flush(T...args)

## Variable Documentation

int loops = 0

Definition at line 61 of file compile_all.cpp.

boost::mutex m_io_monitor

Definition at line 28 of file compile_all.cpp.