Boost: : an asio asynchronous completion port based implementation of a set of open source web framework, but shut down some problems encountered in the process of the program, do not know to have a understand each master relevant knowledge, questions as follows:
Currently used to close the socket, and then close the io_service way
1, if io_service calls directly destroyed after the stop, there will be a probability of abnormal, probably means a worker thread is not quit, io_service were destroyed, but there is no corresponding can find way to control the related sequence, is more than one worker thread,
2, a socket if the call after async_connect, call socket. The cancel () and the socket. The close (), actually did not immediately suspend the link, in fact a worker thread needs to wait for a timeout or interrupt return, the async_connect is completed, there is no other way to shut down, can be faster or sequence control way to shut down?
In the ~ ~
CodePudding user response:
You need to exit the first thread, waiting for all the work thread ends, and then destroying threads use of resources
CodePudding user response:
reference 1st floor VisualEleven response: you need to exit the thread first, waiting for all the work thread ends, and then destruction of threads to use the resources of Is a worker thread exits this is difficult to judge,,, now didn't find the right way, CodePudding user response:
All things are difficult before they are easy, In my opinion, all the gracefully end also difficult, CodePudding user response:
Let a worker thread end actually very simple, Post to a custom event in, Difficult is that many have been delivered (read and write) operation still have returned, you let a worker thread withdrew, Subsequent memory processing may lead to collapse, CodePudding user response:
The reference 3 floor zhao4zhong1 response: all things are difficult before they are easy, In my opinion, all the end also difficult, gracefully Ha ha,,, yes, think grace has close to,,, CodePudding user response:
reference 4 floor shenyi0106 response: let worker thread end is actually very simple, Post to a custom event in, Difficult is that many have been delivered (read and write) operation still have returned, you let a worker thread withdrew, Subsequent memory processing may lead to collapse, Post in only post to one of the worker thread, and can't ensure that each worker thread is idle, many delivery operation, may suspend, but are asynchronous, needs to wait for, this is the waiting time is not well established, violent way is fixed sleep a while wait for them to quit, CodePudding user response:
refer to 6th floor ycf8788 response: Quote: refer to 4th floor shenyi0106 response: Let a worker thread end actually very simple, Post to a custom event in, Difficult is that many have been delivered (read and write) operation still have returned, you let a worker thread withdrew, Subsequent memory processing may lead to collapse, Post in only post to one of the worker thread, and can't ensure that each worker thread is idle, many delivery operation, may suspend, but are asynchronous, needs to wait for, this is the waiting time is not well established, violent way is fixed sleep a while wait for them to quit, Launched a few worker don't record? Launched a few worker post several events, is to ensure that the worker will be normal exit, but couldn't guarantee is free, Whether the CloseHandle CloseSocket or CancelIo cause undo IO events, in the case of high IO, return time is very slow, 3, 5 seconds to more than ten seconds are often appear, especially in the case of multiple connections and high PPS, this returns the waiting time is longer, Sleep may not help you solve the problem of Crash caused by memory is locked, the reference count should be the direction you need to consider, CodePudding user response:
Worker threads out why difficult judgment, judging by the thread to create the returned handle is ok CodePudding user response:
Add 1 layer can solve 1 cut, refer to 7th floor shenyi0106 response: Quote: refer to the sixth floor ycf8788 response: Quote: refer to 4th floor shenyi0106 response: Let a worker thread end actually very simple, Post to a custom event in, Difficult is that many have been delivered (read and write) operation still have returned, you let a worker thread withdrew, Subsequent memory processing may lead to collapse, Post in only post to one of the worker thread, and can't ensure that each worker thread is idle, many delivery operation, may suspend, but are asynchronous, needs to wait for, this is the waiting time is not well established, violent way is fixed sleep a while wait for them to quit, Launched a few worker don't record? Launched a few worker post several events, is to ensure that the worker will be normal exit, but couldn't guarantee is free, Whether the CloseHandle CloseSocket or CancelIo cause undo IO events, in the case of high IO, return time is very slow, 3, 5 seconds to more than ten seconds are often appear, especially in the case of multiple connections and high PPS, this returns the waiting time is longer, Sleep may not help you solve the problem of Crash caused by memory is locked, the reference count should be the direction you need to consider,