Hello everyone,
I'm going to write a program containing two actors and one of them has access to the other ones. I defined one of them as class-based actor which is the main component and other one as function-based actor. I followed the structure of dining philosopher example. I defined some vectors in namespace domain which I guess they will be considered global variables and function-based actor will use them.
First, I need to know the way I choosed to implement my design is correct or not.
second, I've got runtime error when I ran the code. malloc(): memory corruption.
I found out this error happens when I create an actor of the function-based actor. I use linux 14.04 to run this program and I run the program with valgrind to find out memory leak but it didn't help.
the line in them main that leads to abort and error: monitor_actor monitorActor = self->spawn(data_gathering);
namespace {
vector< vector< int > > r1;
vector< vector< int > > r2;
vector< vector< int > > r3;
using B_component
= typed_actor<result<void>(check_with_monitor_atom, int, int, int)>;
B_component::behavior_type data_gathering(B_component::pointer self){
return {
[=](check_with_monitor_atom, int intT1, int intT2,int intT3) -> result<void> {
r1[0] = intT1;
r2[0] = intT2;
r3[0] = intT3;
//
}
};
}
class controller : public event_based_actor {
public:
controller(actor_config& cfg, monitor_actor m)
: event_based_actor(cfg),
monitor_(m) {
set_default_handler(skip);
deciding_.assign([=](decide_atom){
send(monitor_ , check_with_monitor_atom_v, 10, 12, 13);
});
}
behavior_type make_behavior() override {
// start deciding
aout(this) << "start" << endl;
send(this, decide_atom_v);
return deciding_;
}
};
void caf_main(actor_system& system) {
scoped_actor self{system};
monitor_actor monitorActor = self->spawn(data_gathering);
vector< vector< int > > input1;
vector< vector< int > > input2;
vector< vector< int > > input3;
readCpsInput(input1, input2, input3);
self->spawn<controller>(monitorActor, input1, input2, input3, 21, 23);
}
I appreciate if you tell me how I can improve my code and get rid of malloc error.
cheers,
Hanieh