Why and when shouldn't I kill a thread?

后端 未结 6 841
陌清茗
陌清茗 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 14:02

    If you kill your thread the hard way it can leak resources.

    You can avoid it when you design your thread to support cancelation.

    Do not use blocking calls or use blocking calls with a timeout. Receive or send data in smaller chunks or asynchronously.

提交回复
热议问题