我有一個服務器監聽某個端口,並且我創建了幾個分離的線程。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'。 –