blob: 8b36277d045fef94894025057da6a10d88b972f9 (
plain)
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
|
#include <iostream>
#include <glibmm/random.h>
#include <glibmm/thread.h>
#include <glibmm/threadpool.h>
#include <glibmm/timer.h>
namespace
{
Glib::StaticMutex mutex = GLIBMM_STATIC_MUTEX_INIT;
void print_char(char c)
{
Glib::Rand rand;
for(int i = 0; i < 100; ++i)
{
{
Glib::Mutex::Lock lock (mutex);
std::cout << c;
std::cout.flush();
}
Glib::usleep(rand.get_int_range(10000, 100000));
}
}
} // anonymous namespace
int main(int, char**)
{
Glib::thread_init();
Glib::ThreadPool pool (10);
for(char c = 'a'; c <= 'z'; ++c)
{
pool.push(sigc::bind<1>(sigc::ptr_fun(&print_char), c));
}
pool.shutdown();
std::cout << std::endl;
return 0;
}
|