问题
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