Why and when shouldn't I kill a thread?

后端 未结 6 793
陌清茗
陌清茗 2020-12-15 13:35

I am writing a multithreaded socket server and I need to know for sure.

Articles about threads say that I should wait for the thread to return, instead of killing it

6条回答
  •  温柔的废话
    2020-12-15 13:55

    Killing a thread can cause your program to leak resources because the thread did not get a chance to clean up after itself. Consider closing the socket handle the thread is sending on. This will cause the blocking send() to return immediately with an appropriate error code. The thread can then clean up and die peacefully.

提交回复
热议问题