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
| #include<iostream>
#include"idle.h"
#include<pthread.h>
#include"chef_exploit.h"
#include"exploitant.h"
MyIdle* MyIdle::singleton=NULL;
vector<vector<int> > generation_scenar();
/*----------routines des thread---------*/
void* routine_chef_exploit(void* mess);
void* routine_exploit(void* mess);
MyIdle::MyIdle():
m_Box(false, 5),
m_Frame("Resultats"),
m_Label("debut du programme", true)
{
set_title("Intelligence artificielle");
set_border_width(5);
add(m_Box);
m_Label.set_justify(Gtk::JUSTIFY_LEFT);
m_Frame.add(m_Label);
m_Box.pack_start(m_Frame, Gtk::PACK_SHRINK);
//Glib::signal_timeout().connect( sigc::mem_fun(*this, &IdleExample::on_timer), 50 );
Glib::signal_idle().connect( sigc::mem_fun(*this, &MyIdle::on_idle) );
show_all_children();
}
bool MyIdle::on_idle()
{
//déclaration et initialisation des thread
pthread_t thread1,thread2,thread3,thread4,thread5,thread6,thread7;
int rc1,rc2,rc3,rc4,rc5,rc6,rc7;
rc1=pthread_create(&thread1,NULL,routine_chef_exploit,(void*)NULL);
sleep(3);
rc2=pthread_create(&thread2,NULL,routine_exploit,(void*)1);
rc3=pthread_create(&thread3,NULL,routine_exploit,(void*)2);
rc4=pthread_create(&thread4,NULL,routine_exploit,(void*)3);
rc5=pthread_create(&thread5,NULL,routine_exploit,(void*)4);
rc6=pthread_create(&thread6,NULL,routine_exploit,(void*)5);
rc7=pthread_create(&thread7,NULL,routine_exploit,(void*)6);
pthread_join(thread1,NULL);
pthread_join(thread2,NULL);
pthread_join(thread3,NULL);
pthread_join(thread4,NULL);
pthread_join(thread5,NULL);
pthread_join(thread6,NULL);
pthread_join(thread7,NULL);
}
exploitant* creat_exploit(int nb)
{
exploitant* expl;
expl=new exploitant(nb);
return expl;
}
vector<vector<int> > generation_scenar()
{
...
}
void* routine_chef_exploit(void* mess)
{
vector<vector<int> > scenario = generation_scenar();
chef_exploitants* chef1 = new chef_exploitants();
chef1->initi_scenar(scenario);
while(1)
{
sleep(1);
chef1->analyse_pb();
}
}
void* routine_exploit(void* mess)
{
exploitant* exploit=creat_exploit((int)mess);
while(1)
{
sleep(1);
exploit->run();
}
} |