Ãngel GonzÃlez<keisial@gmail.com> wrote:
If you need to explicitely mark like that the points where you want
to accept
cancellation, I would probably find clearer a if (cancel_thread2)
pthread_exit();
(and instead of pthread_cancel(thread_2); you would set to true the volatile
cancel_thread2 variable). But that should be equivalent. If you prefer that way,
it's up to the programmer.
Good point, I'm doing that. I'm not sure about volatile, though[1].
I'm just using the gcc/clang __sync_add_and_fetch(&do_quit, (0|1))
to check/increment: http://bogomips.org/cmogstored.git/patch/?id=f42f8d14
[1] based on my reading of volatile-considered-harmful.txt in Linux
kernel docs, but I think that applies to userspace, too.
Also note that you probably want to continue the for in the EINTR case, so you
don't need to copy the pthread_setcancelstate(), as continuing will hit them.
Since all the accept/epoll_wait calls are already in a loop, I only put
the quit check before entering the waiting syscalls to reduce code size.