threads/154893: pthread_sigmask don't work if mask and oldmask are passed the same pointer

Kostik Belousov kostikbel at gmail.com
Sat Feb 19 19:42:47 UTC 2011


On Sun, Feb 20, 2011 at 04:22:46AM +0900, KOSAKI Motohiro wrote:
> > Your example does not supply oset == 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.
> 
> Oh, I'm sorry. It's cut-n-paste mistake. I did paste old version
> unintensionally.
> 
> void* func2(void* arg)
> {
>         sigset_t old;
>         sigset_t add;
>         int i;
> 
>         sigemptyset(&old);
>         pthread_sigmask(SIG_BLOCK, NULL, &old);
> 
>         printf("before: ");
>         for (i=0; 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=0; i<4; i++)
>                 printf(" %08x", old.__bits[i]);
>         printf("\n");
> 
>         return 0;
> }
> 
> The result is,
> 
> correct case:
> before:  00000000 00000000 00000000 00000000
> after:   20000000 00000000 00000000 00000000
> incorrect case:
> before:  00000000 00000000 00000000 00000000
> after:   00000000 00000000 00000000 00000000
> 
> difference between func and func2 are
> 
> -        pthread_sigmask(SIG_BLOCK, &add, NULL);
> +        pthread_sigmask(SIG_BLOCK, &add, &add);
> 
> 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: 
before:  00000000 00000000 00000000 00000000
after:   20000000 00000000 00000000 00000000
incorrect case: 
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=0; 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=0; 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=0; 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=0; 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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-threads/attachments/20110219/f63dd3e2/attachment.pgp


More information about the freebsd-threads mailing list