我有一个服务器监听某个端口,并且我创建了几个分离的线程。C++线程:如何发送消息到其他长线程?
不仅自己的服务器将永远运行,而且分离的线程将永远运行。
//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;
}
由于我是新来的多线程,我不知道如何在分离线程实现这样nofity
在服务器和check the nofity
。
任何有用的提示将不胜感激。
'std :: condition_variable'。 –