Q:

Need help about OOP-design for sharing variables between classes, which run with a timer indipendently

Let's say I have 2 classes Fly and Bee, which methods (respectively run and loop) runs at differents times.
/* Fly */
using namespace boost::asio 
using namespace boost::posix_time

class Fly { 
... 
deadline_timer timeout_fly_;
char text_fly_;

Fly::Fly( io_service &io): timeout_fly_(io, seconds(4) ) 
{ 
    timeout_fly_.async_wait( boost::bind( &Fly::run, this ) );   
}

Fly::run(void) 
{ 
    std::cout << "Running Fly forever" << std::endl;

     timeout_fly_.expires_at( timeout_fly_.expires_at() + seconds(4)));  
     timeout_fly_.async_wait( boost::bind( &Fly::run, this ) ); 
}

and:
/* Bee */
class Bee { 
... 
deadline_timer timeout_bar_; 
char text_bee_;

Bee::Bee(io_service &io): timeout_bee_(io, seconds(2) ) 
{ 
    timeout_bee_.async_wait( boost::bind( &Bee::loop, this ) );  
}

Bee::loop(void) 
{ 
     std::cout << "Running Bee forever" << std::endl;

     timeout_bee_.expires_at( timeout_bee_.expires_at() + seconds(2) );
     timeout_bee_.async_wait( boost::bind( &Bee::loop, this ) ); 
 }

which are started in the main like:
/* main.cpp */
io_service io_service;

while(1) {

    io_service.run();
}

Now I have the problem that I need to exchange some data between both classes (e.g. the char text ). But I stuck and cannot fix this problem because I don't know how to do that.
I was thinking about passing one class to the other as a reference:
using namespace boost::asio
using namespace boost::posix_time

class Fly {
...
  deadline_timer timeout_fly_;
  Bee bee_;
  char text_fly_;
...

  Fly::Fly(io_service &io, Bee &bee): timeout_fly_(io,seconds(4)), bee_(bee)
  {
    timeout_fly_.async_wait(boost::bind( &Fly::run, this));  
  }

  Fly::run(void)
  {
    std::cout << "Running Fly forever" << std::endl;

    text_fly_ = bee_->getTextInBee();

    timeout_fly_.expires_at(timeout_fly_.expires_at() + seconds(4));
    timeout_fly_.async_wait(boost::bind( &Fly::run, this));
  }

But I'm not sure that this is a good OOP-Design. Furhtermore it will complicate my program. I want to keep it as simple as possible.
Another option could be to create 2 different threads, let them run and save the results with a mutex to synchronize both threads.
How can I exchange generally Data between two classes?

A:

At the end I rewrote my code according to the following pattern.
It consists of a wrapper class, which creates at least three objects:

one class of type Bee;
one class of type Fly;
one class to exhange data between both;

In the wrapper class I have something like the following:
/* Wrapper class */
class Insect {

    /* Class with methods and members for sharing data */
    Data *exchange_data = new Data;

    /* Generate Bee */
    Bee bee;
    /* Generate Fly */
    Fly fly;

    public:
      Insect( boost::asio::io_service &io )
             : bee(io, exchange_data), fly(io, exchange_data);

}

Note that the common shared_data class is now passed at the initialization list when the constructor of the class is called. The class is a member of the wrapper class and once created must be passed to both classes which now are a little bit different:
/* Fly */
using namespace boost::asio 
using namespace boost::posix_time

class Fly { 
... 
deadline_timer timeout_fly_;
char text_fly_;
Data *shared_data;

Fly::Fly( io_service &io, Data *data): timeout_fly_(io, seconds(4)), shared_data(data)
{ 
    timeout_fly_.async_wait( boost::bind( &Fly::run, this ) );   
}

Fly::run(void) 
{ 
    std::cout << "Running Fly forever" << std::endl;

    shared_data->setMember( "I write something here" );

    timeout_fly_.expires_at( timeout_fly_.expires_at() + seconds(4)));  
    timeout_fly_.async_wait( boost::bind( &Fly::run, this ) ); 
}

and
/* Bee */
class Bee { 
... 
deadline_timer timeout_bar_; 
char text_bee_;
Data *shared_data;

Bee::Bee(io_service &io, Data *data): timeout_bee_(io, seconds(2)), shared_data(data)
{ 
    timeout_bee_.async_wait( boost::bind( &Bee::loop, this ) );  
}

Bee::loop(void) 
{ 
     std::cout << "Running Bee forever" << std::endl;

     shared_data->setMember( "I write something else here" );

     timeout_bee_.expires_at( timeout_bee_.expires_at() + seconds(2) );
     timeout_bee_.async_wait( boost::bind( &Bee::loop, this ) ); 
 }

Inside those classes (Bee and Fly) you can point to the same object of type Data using pointers.
In both you can call methods and set or get members of the class Data.
Since both classes are incapsulated inside a thread you need to use a mutex inside Data to avoid that the same ressource or variable is going to be write by both threads at the same time.
I don't pretend to have the best design one can develop. But it works and - despite the use of pointers and other things - it works and it is really easy to understand and to follow the basic idea behind such design.
I hope it can help other people, which have the same trouble.

