How do you handle a thread that has a hung call?

后端 未结 5 697
不思量自难忘°
不思量自难忘° 2020-12-09 21:35

I have a thread that goes out and attempts to make a connection. In the thread, I make a call to a third party library. Sometimes, this call hangs, and never returns. On

5条回答
  •  暖寄归人
    2020-12-09 22:13

    Not a good solution to ever wait on a thread (in any language) indefinitely, especially if you are making external calls. Always use a join with a timeout, or a spin lock that monitors the state of a shared atomic variable until it changes, or you reach a timeout. I'm not a C# guy, but these are all sound concurrency practices.

提交回复
热议问题