Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Jan 2000 22:45:58 -0500
From:      "Mikhail Evstiounin" <evstiounin@adelphia.net>
To:        "Mikhail Evstiounin" <evstiounin@adelphia.net>, <freebsd-questions@FreeBSD.ORG>
Subject:   Re: Volatile variables
Message-ID:  <00cf01bf5fd4$34f2dc20$f8353018@evstiouninadelphia.net.pit.adelphia.net>

next in thread | raw e-mail | index | archive | help
>int allocated = 0;
>char *mem = NULL;
>
>
>void Sigusr1Handler( int siganl )
>{
>    if ( allocateded )
>    {
>        sleep( 60 );    // just for fun
>        mem[ 2 ] = 'F';
>        ...
>
>    }
>}
>
>void Sigusr2Handler( int siganl )
>{
>    if ( allocated )
>    {
>        free( mem );
>        mem = NULL;
>        opened = 0;
>    }
>}
>
>int main( int argc, char* argv[] )
>{
>    mem = ( char* )malloc( 20 );
>    opend = 1;
>    ...
>
>    return 0;
>}

Sorry, shoud be

int allocated = 0;
char *mem = NULL;


void Sigusr1Handler( int siganl )
{
    if ( allocateded )
    {
        sleep( 60 );    // just for fun
        mem[ 2 ] = 'F';
        ...

    }
}

void Sigusr2Handler( int siganl )
{
    if ( allocated )
    {
        free( mem );
        mem = NULL;
        allocated = 0;
    }
}

int main( int argc, char* argv[] )
{
    mem = ( char* )malloc( 20 );
    opend = 1;

    signal( SIGUSR1, Sigusr1Handler );
    signal( SIGUSR2, Sigusr2Handler );

    ...

    return 0;
}

compile, run and send 2 signals to a program -SIGUSR1 and SIGUSR2.
Actually, I am not sure if SIGUSR1 doesn't mask SIGUSR2, but you can
always choose two, when doesn't mask another. And see what is going
to happen if you use or do not use vilotile.

>
>
>
>
>To Unsubscribe: send mail to majordomo@FreeBSD.org
>with "unsubscribe freebsd-questions" in the body of the message



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?00cf01bf5fd4$34f2dc20$f8353018>