Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Feb 2011 21:42:43 +0200
From:      Kostik Belousov <kostikbel@gmail.com>
To:        KOSAKI Motohiro <kosaki.motohiro@gmail.com>
Cc:        freebsd-threads@freebsd.org
Subject:   Re: threads/154893: pthread_sigmask don't work if mask and oldmask are passed the same pointer
Message-ID:  <20110219194243.GL78089@deviant.kiev.zoral.com.ua>
In-Reply-To: <AANLkTinEZwBOoDaU2-7Y9svch1nd4EAyoYyH%2B4V2v_Od@mail.gmail.com>
References:  <201102191809.p1JI9rZi063561@red.freebsd.org> <20110219184348.GK78089@deviant.kiev.zoral.com.ua> <AANLkTinEZwBOoDaU2-7Y9svch1nd4EAyoYyH%2B4V2v_Od@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--fBKP4Km0jCX9yvBB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Feb 20, 2011 at 04:22:46AM +0900, KOSAKI Motohiro wrote:
> > Your example does not supply oset =3D=3D set to the pthread_sigmask,
> > meantime. I really do not see anything wrong with the output of
> > the program that supposed to illustrate the issue.
>=20
> Oh, I'm sorry. It's cut-n-paste mistake. I did paste old version
> unintensionally.
>=20
> void* func2(void* arg)
> {
>         sigset_t old;
>         sigset_t add;
>         int i;
>=20
>         sigemptyset(&old);
>         pthread_sigmask(SIG_BLOCK, NULL, &old);
>=20
>         printf("before: ");
>         for (i=3D0; i<4; i++)
>                 printf(" %08x", old.__bits[i]);
>         printf("\n");
>=20
>         sigemptyset(&add);
>         sigaddset(&add, SIGUSR1);
>         pthread_sigmask(SIG_BLOCK, &add, &add);
>         pthread_sigmask(SIG_BLOCK, NULL, &old);
>=20
>         printf("after:  ");
>         for (i=3D0; i<4; i++)
>                 printf(" %08x", old.__bits[i]);
>         printf("\n");
>=20
>         return 0;
> }
>=20
> The result is,
>=20
> correct case:
> before:  00000000 00000000 00000000 00000000
> after:   20000000 00000000 00000000 00000000
> incorrect case:
> before:  00000000 00000000 00000000 00000000
> after:   00000000 00000000 00000000 00000000
>=20
> difference between func and func2 are
>=20
> -        pthread_sigmask(SIG_BLOCK, &add, NULL);
> +        pthread_sigmask(SIG_BLOCK, &add, &add);
>=20
> That said, To add oset changed sigprocmask() behavior significantly.

Still something is not right :). I copied/pasted the updated func2()
from the mail above, and get
correct case:=20
before:  00000000 00000000 00000000 00000000
after:   20000000 00000000 00000000 00000000
incorrect case:=20
before:  00000000 00000000 00000000 00000000
after:   20000000 00000000 00000000 00000000
on amd64 machine, while code is compiled for 32 bit. I would say
that the output is as expected by me. The old mask is copied out
by kernel after new mask is copied in.

Below is the exact source of the test I used. Could you, please,
confirm that the test is right ?  If not, please send me the
exact source code that demonstrates your issue.

Thanks.

#include <pthread.h>
#include <signal.h>
#include <stdio.h>

void* func(void* arg)
{
        sigset_t old;
        sigset_t add;
        int i;

        sigemptyset(&old);
        pthread_sigmask(SIG_BLOCK, NULL, &old);

        printf("before: ");
        for (i=3D0; i<4; i++)
                printf(" %08x", old.__bits[i]);
        printf("\n");

        sigemptyset(&add);
        sigaddset(&add, SIGUSR1);
        pthread_sigmask(SIG_BLOCK, &add, NULL);
        pthread_sigmask(SIG_BLOCK, NULL, &old);

        printf("after:  ");
        for (i=3D0; i<4; i++)
                printf(" %08x", old.__bits[i]);
        printf("\n");

        return 0;
}

void* func2(void* arg)
{
        sigset_t old;
        sigset_t add;
        int i;

        sigemptyset(&old);
        pthread_sigmask(SIG_BLOCK, NULL, &old);

        printf("before: ");
        for (i=3D0; i<4; i++)
                printf(" %08x", old.__bits[i]);
        printf("\n");

        sigemptyset(&add);
        sigaddset(&add, SIGUSR1);
	pthread_sigmask(SIG_BLOCK, &add, &add);
        pthread_sigmask(SIG_BLOCK, NULL, &old);

        printf("after:  ");
        for (i=3D0; i<4; i++)
                printf(" %08x", old.__bits[i]);
        printf("\n");

        return 0;
}

int main(void)
{
        pthread_t thr;
        void* ret;

        printf("correct case: \n");
        pthread_create(&thr, NULL, func, NULL);
        pthread_join(thr, &ret);

        printf("incorrect case: \n");
        pthread_create(&thr, NULL, func2, NULL);
        pthread_join(thr, &ret);


        return 0;
}

--fBKP4Km0jCX9yvBB
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (FreeBSD)

iEYEARECAAYFAk1gHTIACgkQC3+MBN1Mb4iEbQCg3whUHY7l0Wd98PuzJWT/Ud2H
cFYAn1qOqx8XJRwo4cemsYlUGvAhPkxs
=F2XK
-----END PGP SIGNATURE-----

--fBKP4Km0jCX9yvBB--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110219194243.GL78089>