From: "zhaohang (F)" <zhaohang14@huawei.com>
To: "musl@lists.openwall.com" <musl@lists.openwall.com>
Cc: pengyuanhong <pengyuanhong@huawei.com>
Subject: [musl] some doubts about pthread_cancel
Date: Thu, 16 Jan 2020 12:41:25 +0000 [thread overview]
Message-ID: <59FB1E003EF3A943BD6BAD197ABD4D6A349C51@dggemi524-mbx.china.huawei.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1268 bytes --]
Hi,
I have two doubts about pthread_cancel in musl v1.1.22.
static void cancel_handler(int sig, siginfo_t *si, void *ctx)
{
pthread_t self = __pthread_self();
ucontext_t *uc = ctx;
uintptr_t pc = uc->uc_mcontext.MC_PC;
a_barrier();
if (!self->cancel || self->canceldisable == PTHREAD_CANCEL_DISABLE) return;
1. If try to cancel a thread which is asynchronous and cancel-disable, the handler of SIGCANCEL will return directly here and it seems that the cancellation request is not remained queued. It makes me confused how this thread will be assured to cancel after it enables cancellation?
_sigaddset(&uc->uc_sigmask, SIGCANCEL);
if (self->cancelasync || pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) {
uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel;
#ifdef CANCEL_GOT
uc->uc_mcontext.MC_GOT = CANCEL_GOT;
#endif
return;
}
__syscall(SYS_tkill, self->tid, SIGCANCEL);
2. Why send SIGCANCEL again here? I think self->cancel is enough to judge whether a deferred thread has been cancelled, and furthermore SIGCANCEL is added to uc->uc_sigmask so that SIGCANCEL will not be handled again.
}
[-- Attachment #2: Type: text/html, Size: 7710 bytes --]
next reply other threads:[~2020-01-16 12:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-16 12:41 zhaohang (F) [this message]
2020-01-16 13:41 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=59FB1E003EF3A943BD6BAD197ABD4D6A349C51@dggemi524-mbx.china.huawei.com \
--to=zhaohang14@huawei.com \
--cc=musl@lists.openwall.com \
--cc=pengyuanhong@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).