mercredi 30 mars 2016

C++ thread: how to send message to other long-live thread?

I have a server listening to some port, and I create several detached threads.

Not only the server it self will run forever, but also the detached threads will run forever.

//pseudocode
void t1_func()
{
   for(;;)
   {
     if(notified from server)
         dosomething();
   }
}
thread t1(t1_func);
thread t2(...);
for(;;)
{
  // read from accepted socket
  string msg = socket.read_some(...);
  //notify thread 1 and thread 2;
}

Since I am new to multithreading, I don't know how to implement such nofity in server, and check the nofity in detached threads.

Any helpful tips will be appreciated.

Aucun commentaire:

Enregistrer un commentaire