bonjour, je souhaite utiliser boost::thread et je n'arrive pas à la faire fonctionner :-(
file main.cpp
-----------------------------
1 #include <iostream>
2 #include <boost/thread/thread.hpp>
3 #include <boost/thread/mutex.hpp>
4 #include <boost/bind.hpp>
5
6 boost::mutex io_mutex;
7
8 void count(int id)
9 {
10 for (int i = 0; i < 110; ++i)
11 {
12 boost::mutex::scoped_lock lock(io_mutex);
13 std::cout << id << ": " << i << std::endl;
14 }
15 }
16 int main(int argc, char* argv[])
17 {
18 boost::thread thrd1(boost::bind(&count, 1));
19 boost::thread thrd2(boost::bind(&count, 2));
20 thrd1.join();
21 thrd2.join();
22 return 0;
23 }
-----------------------------
source de l'exemple : http://aszt.inf.elte.hu/~gsd/klagenf...l/ch03s06.html
-----------------------------
g++ -lboost_thread -lpthread main.cpp -o main && ./main
1: 0
1: 1
1: 2
1: 3
1: 4
1: 5
1: 6
1: 7
1: 8
1: 9
2: 0
2: 1
2: 2
2: 3
2: 4
2: 5
2: 6
2: 7
2: 8
2: 9
-----------------------------
visiblement les fonctions count(1) et count(2) s'exécutent l'une après l'autre :-(
par avance merci et bon courage.
PS : avec l'autre exemple j'obtiens des résultats semblables
Partager