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:from:date:message-id:subject:to | |
:content-type; q=dns; s=default; b=tB1lehTXyWivWyjIW0bh7+sSrfxiJ | |
Ktng3oP3xvqvL9aJ6su6otFLi5X6739D0TThuH9mA3znnlh9WfSQd0q2vCsir07c | |
k2v4owq0uVdNEM25qgZEgv/JVLVtUjaT65wRKefEbN4r2Mgm5dI7L+i6FqWN0h0l | |
+PHuVW5Xj7o4eQ= | |
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:from:date:message-id:subject:to | |
:content-type; s=default; bh=fu71LC6/1bWgNMupUpoG3qnPC9c=; b=Zkg | |
ZV8GizJbbCDWgZpFZAu3l5wsZifzWSslzMiGIeUSePZpeT1y+W7UusJw2eKm92V2 | |
DPUM221on0tRMhR3ZCbIV7Rl/60GsAQOkOlo4tVFZls3qXBLdrExw2GSdm4Lk/kx | |
57sge4OaTwwJkt8dSpDJEH/NHwRFbbHwiahkcAJ4= | |
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=CORRECT, 100000, srv, HX-Gm-Message-State:APjAAAV |
X-HELO: | mail-io1-f49.google.com |
DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=MgBINewQxfSm7I6+XjbNjns1a4dumOaY+AHrjiiKGmM=; b=tSAjANSZUCETY7SymFTW+QX7h/Lnpp1fqP8oUGBnZPuOrvBd8iH+SwtGDl0x6NkUds EtOzUIUXvK60xCJX8jxLoYUoAgB+rUk/gAGQLZIzflIH7JoJ/5s5gDbuvljizlggOvaR YNx+bUGzdjSS4XQwo2sluyNj48fX9g1Jqwk0A= |
MIME-Version: | 1.0 |
From: | Kenton Varda <kenton AT cloudflare DOT com> |
Date: | Sat, 6 Jul 2019 15:46:01 -0700 |
Message-ID: | <CAJouXQne09R+j+k+ZNw5fsZTFqDG5_9iwm9KQnxHoycL+ap_KQ@mail.gmail.com> |
Subject: | sigpending() incorrectly returns signals pending on other threads |
To: | cygwin AT cygwin DOT com |
--000000000000d3680a058d0afb1d Content-Type: text/plain; charset="UTF-8" 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 --000000000000d3680a058d0afb1d Content-Type: text/x-csrc; charset="US-ASCII"; name="test-sigpending.c" Content-Disposition: attachment; filename="test-sigpending.c" Content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lbXB0 eXNldCgmbWFzaykpOwogIHN5cyhzaWdhZGRzZXQoJm1hc2ssIFNJR1VTUjEp KTsKICBzeXMoc2lncHJvY21hc2soU0lHX1VOQkxPQ0ssICZtYXNrLCBOVUxM KSk7CgogIHB0aHJlYWRfam9pbihjaGlsZFRocmVhZCwgTlVMTCk7Cn0KCg== --000000000000d3680a058d0afb1d 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 --000000000000d3680a058d0afb1d--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |