thread_example.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <boost/thread.hpp>
4 #include <boost/shared_ptr.hpp>
5 using namespace std;
6 
7 typedef enum
8 {
13 
14 class Candidate
15 {
16  public:
17 
18  typedef boost::shared_ptr<Candidate> Ptr;
19 
20  Candidate(double input_image, uint priority_, uint id_)
21  {
22  classification = UNKNOWN;
23 
24  id = id_;
25  image = input_image;
26  priority = priority_;
27  }
28 
29 
30  void classify()
31  {
32  t = boost::thread(boost::bind(&Candidate::do_classfication,this));
33  }
34 
36  {
37  switch(classification)
38  {
39  case VEHICLE:
40  return "vehicle";
41  case PEDESTRIAN:
42  return "pedestrian";
43  case UNKNOWN:
44  return "unknown";
45  }
46 
47  return "unknown";
48  }
49 
51  {
52  //Run the heady classifcation code from pedro
53  int c = 0;
54  cout<<"Processing image"<<endl;
55  while(c<100)
56  {
57  c++;
58  boost::this_thread::sleep(boost::posix_time::milliseconds(100));
59  }
60 
61  classification = PEDESTRIAN;
62 
63  cout<<"done"<<endl;
64  }
65 
66  uint id;
67  uint priority;
68  TypeClassification classification;
69  double image;
70  boost::thread t;
71 
72 };
73 
74 
75 int var1;
76 
78 {
79  while(1)
80  {
81  cout<<"in secondary loop: "<< var1++ <<endl;
82  boost::this_thread::sleep(boost::posix_time::milliseconds(500));
83  }
84 }
85 
86 int main()
87 {
88 
89  vector<Candidate::Ptr> candidate_list;
90 
91 
92  cout<<"i'm alive"<<endl;
93 
94 
95  for(uint i=0;i<5;i++)
96  {
97  Candidate::Ptr candidate = Candidate::Ptr(new Candidate(0.0,i,i));
98  candidate_list.push_back(candidate);
99  }
100 
101 
102  for(uint i=0;i<candidate_list.size();i++)
103  {
104  if(candidate_list[i]->priority > 2)
105  candidate_list[i]->classify();
106  }
107 
108  for(uint i=0;i<candidate_list.size();i++)
109  {
110  candidate_list[i]->t.join();
111  }
112 // while(1)
113 // {
114 // cout<<endl;
115  for(uint i=0;i<candidate_list.size();i++)
116  {
117  cout<<"candidate: "<<candidate_list[i]->id<<" priority: "<<candidate_list[i]->priority<< " classification: "<<candidate_list[i]->getClassification()<<endl;
118  }
119 
120 }
void do_classfication()
TypeClassification
void separte_loop()
Candidate(double input_image, uint priority_, uint id_)
Candidate validation.
boost::thread t
TypeClassification
string getClassification()
int main()
boost::shared_ptr< Candidate > Ptr
int var1
void classify()


multimodal_pedestrian_detect
Author(s): Rui Azevedo
autogenerated on Mon Mar 2 2015 01:32:27