开发者

pthread_join causes termination on accept()

开发者 https://www.devze.com 2023-03-11 22:00 出处:网络
I have an attached server thread blocked on an accept() waiting for connections.Externally I try to terminate the thread by calling pthread_cancel(), followed by pthread_join().Upon calling the join,

I have an attached server thread blocked on an accept() waiting for connections. Externally I try to terminate the thread by calling pthread_cancel(), followed by pthread_join(). Upon calling the join, my program terminates with a SIGABRT.

I am, more than likely going to the detach the thread, and make it select(开发者_Python百科) with a timeout to check for connections, so I can then "signal" it to quit. So, I know this is a solution, but being the curious type, I was wondering why the first solution doesn't work.


I think you're getting the program termination SIGABRT because of the pthread_cancel() -- when the blocked thread gets the signal, it probably dies. The signal delivery doesn't happen until after the call to pthread_cancel() has returned, so it just looks like it occurs because of the join call.

To check and see if my thoughts are right, I would insert a while(1); loop after the pthread_cancel() to see if you still get the SIGABRT.

0

精彩评论

暂无评论...
验证码 换一张
取 消