delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2015/01/19/11:21:30

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:date:from:to:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; q=dns; s=
default; b=IYDZmQuzKIahGIQxuPpOkI4XBIJTVdrgKAXncerYmMSairgvofnP9
TrgIq+JHeo6nxzcAQCka9DCjn8ciEKrT61ydfcvwopVOLduriPi+ssaN1DC4GaG/
Ct0poriUuXuDh0JmiZNrlU00qlfD8QGASnUw1r5sBomeC41yGx9bBU=
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:date:from:to:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; s=default;
bh=qAUfVp3q+qcNU/XuBFRbrGNDISA=; b=fafpjzLGAI2b/4bo6PUO8SQIkmj2
KWyqBh71jzITuciWFeGwJ46sjUR1Ffce0jLVqwM1U7LttnFQwXJJvhbiER4vJ1f8
rNT9gepJsf4IkZVHuDSobyN++EYAbjJNkI4WtAag6drNDRYChcSCUTEQDffBQ2/S
zPw+vRvf0yzVrkI=
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-Virus-Found: No
X-Spam-SWARE-Status: No, score=-5.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2
X-HELO: calimero.vinschen.de
Date: Mon, 19 Jan 2015 17:21:05 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Using signals to unblock calls to msgrcv() in a multi-threaded process (Cygwin v1.7.33)
Message-ID: <20150119162105.GR3122@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <6E8492D726F2EA4D8D5418F55704603F01028679FF24 AT THSONEP02CMB02P DOT one-02-priv DOT grp> <20150119103842 DOT GD10055 AT calimero DOT vinschen DOT de>
MIME-Version: 1.0
In-Reply-To: <20150119103842.GD10055@calimero.vinschen.de>
User-Agent: Mutt/1.5.23 (2014-03-12)

--e8/wErwm0bqugfcz
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Jan 19 11:38, Corinna Vinschen wrote:
> On Jan 19 08:29, SCOTT Damien wrote:
> > I have a multi-threaded process running under Cygwin that receives
> > messages from several IPC message queues (built using Cygwin's gcc,
> > version 4.8.3).=C2=A0 The listener for each queue runs in its own threa=
d,
> > each of which is created from the main thread.=C2=A0 Each listener is u=
sing
> > a blocking call to msgrcv().=C2=A0 I want the main thread to be able to=
 use
> > pthread_kill() to send a SIGUSR1 signal to each listening thread to
> > cause it to abandon its call to msgrcv() and then exit.=C2=A0=20
> >=20
> > My approach has been to create a signal mask containing just SIGUSR1
> > and associate this with a signal handler (although the signal handler
> > contains no functionality, since all I need is for the blocking call
> > to msgrcv() to be abandoned).=C2=A0 I initially set the signal mask to
> > block in the main thread, which should then be inherited by each of
> > the created listening threads.=C2=A0 I only unblock the signal mask aro=
und
> > the call to msgrcv() in each listening thread.
> >=20
> > I have included a simplified version of my code below.=C2=A0 I usually
> > don't see any evidence of the SIGUSR1 signal being received by either
> > of the listener threads.=C2=A0 Occasionally the first thread unblocks as
> > expected but I have never seen both threads unblock.=C2=A0 If I change =
my
> > code so that there is only a single listener thread, then everything
> > works correctly every time.=C2=A0 Changing the msgrcv() call to a sleep
> > call also allows unblocking to occur correctly.=C2=A0 Note that this
> > simplified code does not include removal of the created queues (since
> > it never manages to exit anyway) so I manually remove these after each
> > run using the ipcrm command.
> >=20
> > Example output:
> >=20
> > Running thread 2 with queue Id =3D 1441792
> > Running thread 1 with queue Id =3D 1179649
> > About to kill thread 1
> >=20
> > Is there an issue with the Cygwin implementation of signal handling,
> > or is there a problem with my code?=C2=A0 Any help would be much
> > appreciated.
>=20
> It's an issue with the Cygwin code, probably.  The msgrcv code ultimately
> hangs in a blocking ReadFile call on a named pipe, and this call is
> non-interruptible.  Changing that requires a bigger change in Cygwin
> which will take time.

...or not.  I'm not sure I can fix that for the upcoming 1.7.34 release,
but it seems cygserver is using the wrong signal handle.  At one point
the signal handling got changed a lot to improve per-thread signalling,
and, as far as I can see, the cygserver code still assumes a global
per-process signal handle, which is the old version from before the
change.

Just to let you know I'm looking into that.  Stay tuned.

Oh, btw., there's a bug in your testcase:

  int id =3D msgget(key, IPC_CREAT|IPC_EXCL);

This call is missing the permission bits, so the permissions are set
to 000.  The permission bits should be added:

  int id =3D msgget(key, IPC_CREAT|IPC_EXCL|S_IWUSR|S_IRUSR);


Corinna

--=20
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

--e8/wErwm0bqugfcz
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBAgAGBQJUvS7xAAoJEPU2Bp2uRE+grHoP/jWY9hF2PPVY75U1pzduhSEY
JaWa1nL30yV4b7NeIOgwBX0FuVgGg79QcPRn0Qn8k9ZH1u/hT0FQMnp3iJxRYNoj
Uq2wNn3AhsQRI1b3MEPYPSOjNQXa/tweHAdg+rFkTl8tBqOqr3p8DTZhQbm/4DDI
oBBW7u/Nt5/nQO2GvgPOWkPbFfhh1rorwtCWmdxLoaDgNY765WhIvJT5MjtO5hk7
5cMrMcs0iKVAJAwzD8s2HAN1f2HQP/ZNg7koFnSsx7Wyr+H3JrPIMK+A9N9z4TpM
4/L04YAVgJKreQqJhAIgLkMx9mEiSjXg/pvVBvMqBxNGqF8c+EDHK3ufnUhrnBZp
/G3Xrgo/JcggvD2tpgY+/npnpfX+2o1orR7LEJM2cjAnLuvM48qZo8hAi7l1Gyxz
is0mgXVXJwj2VIatbtC/vm4Qrriikw+mPo0Vmt03XWUmfZKquAbOIHpBKYLcjhIq
6yOtHTFuk1LCw74n7qYXj4g+n/FPDhp6Xvk8w5oxY+kKqyjXbVfLaiXeo9/JcfJM
X/qRNlzuezczm95BdUtHqtmLue+9CyMcFHi5E/6axQQpkexTSjAFNLviOBsUINKs
qjezvwzoiwAm6OG2sv3q/FGr0k+n96LsOo6nmO8j5EqMj37h/CRFRJjytIGotudw
TSIsJBFNRyxMd4Pe883b
=Tk+3
-----END PGP SIGNATURE-----

--e8/wErwm0bqugfcz--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019