From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.2 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by inbox.vuxu.org (OpenSMTPD) with SMTP id 10dd3d4a for ; Thu, 16 Jan 2020 12:41:49 +0000 (UTC) Received: (qmail 5904 invoked by uid 550); 16 Jan 2020 12:41:47 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 5866 invoked from network); 16 Jan 2020 12:41:45 -0000 From: "zhaohang (F)" To: "musl@lists.openwall.com" CC: pengyuanhong Thread-Topic: some doubts about pthread_cancel Thread-Index: AdXMafZ/zOEjFqUMQV65t+RUVz+C2A== Date: Thu, 16 Jan 2020 12:41:25 +0000 Message-ID: <59FB1E003EF3A943BD6BAD197ABD4D6A349C51@dggemi524-mbx.china.huawei.com> Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.173.221.92] Content-Type: multipart/alternative; boundary="_000_59FB1E003EF3A943BD6BAD197ABD4D6A349C51dggemi524mbxchina_" MIME-Version: 1.0 X-CFilter-Loop: Reflected Subject: [musl] some doubts about pthread_cancel --_000_59FB1E003EF3A943BD6BAD197ABD4D6A349C51dggemi524mbxchina_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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 =3D __pthread_self(); ucontext_t *uc =3D ctx; uintptr_t pc =3D uc->uc_mcontext.MC_PC; a_barrier(); if (!self->cancel || self->canceldisable =3D=3D PTHREAD_CANCEL_DIS= ABLE) 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 cancel= lation 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 >=3D (uintptr_t)__cp_begin && pc < (u= intptr_t)__cp_end) { uc->uc_mcontext.MC_PC =3D (uintptr_t)__cp_cancel; #ifdef CANCEL_GOT uc->uc_mcontext.MC_GOT =3D CANCEL_GOT; #endif return; } __syscall(SYS_tkill, self->tid, SIGCANCEL); 2. Why send SIGCANCEL again here? I think self->cancel is enough to judge w= hether a deferred thread has been cancelled, and furthermore SIGCANCEL is a= dded to uc->uc_sigmask so that SIGCANCEL will not be handled again. } --_000_59FB1E003EF3A943BD6BAD197ABD4D6A349C51dggemi524mbxchina_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi,

 

I have two doubts about pthread= _cancel in musl v1.1.22.

 

static void cancel_handler(int = sig, siginfo_t *si, void *ctx)

 {

     &= nbsp;   pthread_t self =3D __pthread_self();

     &= nbsp;   ucontext_t *uc =3D ctx;

     &= nbsp;   uintptr_t pc =3D uc->uc_mcontext.MC_PC;

     &= nbsp;    a_barrier();

     &= nbsp;   if (!self->cancel || self->canceldisable =3D= =3D PTHREAD_CANCEL_DISABLE) return;

 

1. If try to cancel a thread wh= ich is asynchronous and cancel-disable, the handler of SIGCANCEL will retur= n 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?=

     &= nbsp;    _sigaddset(&uc->uc_sigmask, SIGCANCEL);=

     &= nbsp;    if (self->cancelasync || pc >=3D (uintpt= r_t)__cp_begin && pc < (uintptr_t)__cp_end) {<= /p>

     &= nbsp;           uc-&= gt;uc_mcontext.MC_PC =3D (uintptr_t)__cp_cancel;

 #ifdef CANCEL_GOT

     &= nbsp;           uc-&= gt;uc_mcontext.MC_GOT =3D CANCEL_GOT;

 #endif<= /p>

     &= nbsp;           retu= rn;

     &= nbsp;   }

     &= nbsp;    __syscall(SYS_tkill, self->tid, SIGCANCEL);=

 

2. Why send SIGCANCEL again her= e? 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.

 }

--_000_59FB1E003EF3A943BD6BAD197ABD4D6A349C51dggemi524mbxchina_--