안드로이드/포팅
pthread_cancel()
code cat
2013. 2. 4. 15:59
쉽게 요약하자면 C library가 고작 pthread_cancle지원하자고 너무 커지기 때문에 바이오닉 C에서는 지원 안한단다. 대신 pthread_cleanup_push()와 pthread_cleanup_pop()은 지원하니까 적절히 사용하자.pthread_cancel():pthread_cancel() will *not* be supported in Bionic, because doing this wouldinvolve making the C library significantly bigger for very little benefit.Consider that:- A proper implementation must insert pthread cancellation checks in a lotof different places of the C library. And conformance is very difficultto test properly.- A proper implementation must also clean up resources, like releasingmemory, or unlocking mutexes, properly if the cancellation happens in acomplex function (e.g. inside gethostbyname() or fprintf() + complexformatting rules). This tends to slow down the path of many functions.- pthread cancellation cannot stop all threads: e.g. it can't do anythingagainst an infinite loop- pthread cancellation itself has short-comings and isn't very portable(see http://advogato.org/person/slamb/diary.html?start=49 for example).All of this is contrary to the Bionic design goals. If your code depends onthread cancellation, please consider alternatives.Note however that Bionic does implement pthread_cleanup_push() andpthread_cleanup_pop(), which can be used to handle cleanups that happen whena thread voluntarily exits through pthread_exit() or returning from itsmain function.