-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathping_pong.cpp
152 lines (106 loc) · 2.54 KB
/
ping_pong.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* File: main.cpp
* Author: maxds
*
* Created on 4 novembre 2011, 17:14
* Ce fichier illustre un ping pong entre acteurs
*/
#include <cstdlib>
#include <iostream>
#include "Actor.h"
#include "Closures.h"
#include "ThreadPool.h"
#include <stack>
#include <algorithm>
#include <assert.h>
using namespace std;
/**
* Une fonction
* @param arg
* @return
*/
class UneFonction: public virtual Functional::Routine<int,int>{
public:
int invok(int &arg){
std::cout << "Dans UneFonction"<< std::endl;
return 0;
}
};
class Ping : public Acting::Actor{
private:
Acting::Actor* pong;
int message;
public:
void SetPong(Acting::Actor* pong){
this->pong = pong;
}
Ping():Actor(){
this->message = this->GetId();
this->pong = pong;
}
virtual void act(){
int tag;
for(int i=0;i<10;i++){
printf("actor[%d] step [%d]: %s --%d--> %s\n",this->GetId(),i,this->GetName().c_str(),message,this->pong->GetName().c_str());
tag=this->send<int>(this->pong,&message,0);
sleep(this->GetId()+2);
this->receive<int>(pong,0,&message);
printf("actor[%d] step [%d]: %s <--%d-- %s\n",this->GetId(),i,this->GetName().c_str(),message,this->pong->GetName().c_str());
message++;
}
}
};
class Node : public Acting::Actor{
private:
Acting::Actor* successeur;
Acting::Actor* predeccesseur;
public:
Node(Acting::Actor* successeur,Acting::Actor* predeccesseur):Actor()
{
this->successeur=successeur;
this->predeccesseur=predeccesseur;
}
virtual void act(){
int message = 100;
this->send<int>(this->successeur,&message,0);
this->receive<int>(this->predeccesseur,0,&message);
}
};
typedef struct {
int x;
int y;
float z;
float *w;
} data_t;
int main() {
list<data_t> liste;
data_t t ;
t.x=2;
liste.push_front(t);
//liste.remove(&t);
list<data_t>::iterator it = liste.begin();
liste.erase(it);
assert(liste.size() == 0);
const int thread_count =6;
Acting::Actor::Init();
Ping* ping = new Ping();
Ping* pong = new Ping();
ping->SetName(string("PING"));
pong->SetName(string("PONG"));
ping->SetPong(pong);
pong->SetPong(ping);
/*
renommer cette methode comme méthode d'instance, ivoquant une méthode
static
*/
/**
En gros faire en sorte que:
ping->start();
pong->start();
*/
ping->start();
pong->start();
//////////////////////////////////////////////////
Acting::Actor::Finit();
return 0;
}