Problem with getline and threads

梦想的初衷 提交于 2019-12-22 11:08:55

问题


I have client that works on 2 threads. One is sending data and second one is receiving data. In sending data I have std::getline(std::cin,string). Now in this thread I have infinite loop which ends if second threads end or if user put EXIT command, everything work great expect that when second thread is ended and infinite loop is ended, program still waits for pressing button because of std::getline.
Now to question:

How can I send data to getline to "fake" pressing button so I don't have to press button to end program?

Second question I have server which for every client runs another thread and main thread of server accepts new connections, it is also working great. Client are stored in std::list. Every thread has inifnite loop which receive data from clients. If client curse too much he is getting kicked form the server but here is the problem when user do that I just break from infite loop and thread is ending but I would also like to erase client from list so in main thread of program I must check everytime if any of thread returned right value, and if it did erasing element from list?

来源:https://stackoverflow.com/questions/6408584/problem-with-getline-and-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!