delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:mime-version:references:in-reply-to:from:date | |
:message-id:subject:to:content-type; q=dns; s=default; b=igch3Nv | |
BWYJLMT7DvWhk6NWp/D9BbRM66weyVgcRyup1fiSIFtjt2/lV8ZwS16pYFzE0WHK | |
TclzY2Npq9yZluJToTURPLg14fZaiU2TSjSumzUsrZbOIMlrh39Xucv1btW8XceK | |
wGKNYrb03wzu+DzaqRFbFVRUxAgl+9YPGjao= | |
DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:mime-version:references:in-reply-to:from:date | |
:message-id:subject:to:content-type; s=default; bh=BKs+0JbDSArxF | |
boh3yg4IoAD+lA=; b=OUhoD2mt2xsN7fQEjDtwzufJBZEtMVE7k7HTCdSYrCclz | |
5phnqcJnwbB3mf3Vm+T1X5aWbFlHlI/TL5aajrvwrR0QUElGI81teyyuC7fXGh+f | |
LgZrkjArNK3g2o2kqtmhkuHwDp3vdaC/xwoYW8HIQOvUox4IHAkOdcPpFfy1Kk= | |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
Authentication-Results: | sourceware.org; auth=none |
X-Spam-SWARE-Status: | No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=varda, Varda |
X-HELO: | mail-io1-f48.google.com |
DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=YooNbMZMwUlQTiOkxOl+ohutGOJHBnY+TKy4uhhZ4Jg=; b=ZmAklq80dj+z7c9G9PtMzHjA3ES6sIT38QQXIA3jOvLBGkPgjbjEP+GeWBh9jLds3t Hn2VN3a/7X4bjz7VkYNaQC+kkQhjdHpOe7b56ezed/acJb9YbNs6fhUVeS5o1K6sjSZn 4yw8ecqDKryZVodCghawbV2yghx+V6pxojwJI= |
MIME-Version: | 1.0 |
References: | <CAJouXQne09R+j+k+ZNw5fsZTFqDG5_9iwm9KQnxHoycL+ap_KQ AT mail DOT gmail DOT com> |
In-Reply-To: | <CAJouXQne09R+j+k+ZNw5fsZTFqDG5_9iwm9KQnxHoycL+ap_KQ@mail.gmail.com> |
From: | Kenton Varda <kenton AT cloudflare DOT com> |
Date: | Sat, 6 Jul 2019 19:15:45 -0700 |
Message-ID: | <CAJouXQksOsqWV=pVAJrXPn2FKtAyUO3QTxpugJ9R9rLGEN91UQ@mail.gmail.com> |
Subject: | Re: sigpending() incorrectly returns signals pending on other threads |
To: | cygwin AT cygwin DOT com |
--000000000000e9f91d058d0de9f9 Content-Type: text/plain; charset="UTF-8" I found a second problem which may or may not be related: If two threads use pthread_kill() to send each other the same signal, such that the signal should be separately pending on both threads at the same time, only one of the two signals is actually queued. It seems that pthread_kill() is ignored if the same signal is already pending on some other thread. I've attached another demo program where two threads send each other the same signal at the same time. On Linux and Mac, both are delivered. On Cygwin, one or the other signal is delivered randomly, but never both. Same version: CYGWIN_NT-6.1 3.0.7(0.338/5/3) 2019-04-30 18:08 -Kenton On Sat, Jul 6, 2019 at 3:46 PM Kenton Varda <kenton AT cloudflare DOT com> wrote: > > Hello Cygwin, > > According to the (Linux) man page: "sigpending() returns the set of > signals that are pending for delivery to the calling thread" > > However, on Cygwin, sigpending() seems to return the set of signals > pending on any thread, as shown in the attached test program. > > Among other things, this can cause deadlocks in programs which use > sigpending() to check for pending signals, then use sigsuspend() to > induce delivery of the specific signals that are pending. Because the > signal is not actually pending on the current thread, sigsuspend() > will unexpectedly block, potentially forever. > > Output of test program: > $ uname -srv > CYGWIN_NT-6.1 3.0.7(0.338/5/3) 2019-04-30 18:08 > $ gcc -std=c11 -Wall test-sigpending.c -o test-sigpending -pthread && > ./test-sigpending > sending signal to child thread with pthread_kill()... > sigpending() says signal is pending in main thread (WRONG) > sigpending() says signal is pending in child thread (CORRECT) > received signal in child thread (CORRECT) > > The program works correctly on Linux. > > -Kenton --000000000000e9f91d058d0de9f9 Content-Type: text/x-csrc; charset="US-ASCII"; name="test-pthread-kill.c" Content-Disposition: attachment; filename="test-pthread-kill.c" Content-Transfer-Encoding: base64 Content-ID: <f_jxsb8b5o0> X-Attachment-Id: f_jxsb8b5o0 I2RlZmluZSBfR05VX1NPVVJDRSAxCgojaW5jbHVkZSA8cHRocmVhZC5oPgoj aW5jbHVkZSA8c2lnbmFsLmg+CiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVk ZSA8dW5pc3RkLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0 cmluZy5oPgoKI2RlZmluZSBzeXMoY29kZSkgaWYgKChjb2RlKSA8IDApIHsg cGVycm9yKCNjb2RlKTsgZXhpdCgxKTsgfQoKcHRocmVhZF90IG1haW5UaHJl YWQ7CnB0aHJlYWRfdCBjaGlsZFRocmVhZDsKCnVuc2lnbmVkIGludCByZWNl aXB0cyA9IDA7Cgp2b2lkIGhhbmRsZXIoaW50IHNpZ25vLCBzaWdpbmZvX3Qq IHNpZ2luZm8sIHZvaWQqIGNvbnRleHQpIHsKICBpZiAocHRocmVhZF9lcXVh bChwdGhyZWFkX3NlbGYoKSwgbWFpblRocmVhZCkpIHsKICAgIHByaW50Zigi cmVjZWl2ZWQgc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Q09SUkVDVClc biIpOwogIH0gZWxzZSBpZiAocmVjZWlwdHMgPT0gMSB8fCByZWNlaXB0cyA9 PSAyKSB7CiAgICBwcmludGYoIm9ubHkgb25lIHRocmVhZCByZWNlaXZlZCBz aWduYWwgKFdST05HKVxuIik7CiAgfSBlbHNlIHsKICAgIHByaW50Zigic2ln bmFsIG5vdCBkZWxpdmVyZWQgYXQgYWxsIChXUk9ORylcbiIpOwogIH0KfQoK --000000000000e9f91d058d0de9f9 Content-Type: text/plain; charset=us-ascii -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple --000000000000e9f91d058d0de9f9--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |