this sender thread once after called first time finish execution. couldn't able resume sender thread. there mechanism in c++ resume threads.
void clientsocket::sender() { char buf[1024]; //readbuffer = m_ptrsendstream->read_adt(filepath); //readstream(); //cout << readbuffer.str()<<endl; cout << "write stream send through socket\n" << endl; cin >> buf; if (isconnected == 0) { //send(clientsock, readbuffer.str().c_str(), strlen((char *)readbuffer.str().c_str()), 0); send(clientsock, buf, strlen(buf), 0); cout << "sending stream :\n"<<endl << buf << endl; } } //this thread creation happens , join() happens. int main(int argc, char *argv[]) { clientsocket objsocket(argv[1]); sender_thread = make_shared<thread>([&objsocket]() { objsocket.sender(); }); try { if (sender_thread->joinable()) sender_thread->join(); }
no, once thread has joined it's done , need create new one.
if have pattern creating new threads might worthwhile think using threadpool avoid overhead of spawning new threads.
in addition, if related networking it's best avoid using threads , instead use asynchronous boost::asio.
Comments
Post a Comment