Unix

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • HPUX-DEVTOOLS: pthread_cancel doesn't work

    7 answers - 819 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    >From: "Manish Katiyar" <mkatiyar (AT) gmail (DOT) com>
    >Even after enabling cancellation pthread_cancel is not getting caught.
    >Can anyone please identify the issue? When I set it to asynchronous it
    >works.

    I assume that since you aren't calling any libc functions, there is no
    place where synchronous cancels can be caught.
    int main(){
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL) ;
    pthread_cleanup_push(hndlr,NULL);
    pthread_cancel(pthread_self());
    for(;;);
    You just have that infinite loop.
    (I assume you know you probably shouldn't cancel the main thread?)
    To leave this mailing list, send mail to majordomo (AT) cxx (DOT) cup.hp.com
    with the message UNSUBSCRIBE hpux-devtools
  • No.1 | | 1181 bytes | |

    Hi Dennnis/Rohit,

    Thanks for your responsesCould you please explain me how does HPUX
    pthread_cancel works in case of blocking system calls. EgIf i am in
    middle of read system call and get a cancellation signal. read will return
    with EINTR am i right ?and after that cancel signal still exists
    or is said to be deliveredcoz If i do a testcancel after that I can
    still see that signal

    thanks in advance.

    9/13/06, Manish Katiyar <mkatiyar (AT) gmail (DOT) comwrote:

    Hi Dennis,

    Thanks for the responseyes main thread should not be cancelled but I
    see this behaviour when i create a thread alsojust to keep the code
    short I cancelled the main thread.

    "I assume that since you aren't calling any libc functions, there is no
    place where synchronous cancels can be caught."

    I partially agree with this coz as I know libc functions just act as
    additional cancellation points. Even if they are not there and thread
    behaviour is deferred, signal should be delivered to the thread at some
    point and this is what I expect.

    Any other suggestions ?
    >
    >
    >
  • No.2 | | 3556 bytes | |

    Hi Rohit,

    Below is my code snippet and its output

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

    pthread_t stid,ftid;

    void hndlr(void *a){
    int oldstate;
    printf("I am in pthread handler\n");
    return ;
    }
    void *fstart(void *tid){
    printf("Sending cancel signal to another thread \n");
    pthread_cancel(stid);
    return NULL;
    }

    void *sstart(void *tid){
    char buff[100];
    int n;
    pthread_cleanup_push(hndlr,NULL);
    printf("\nI have pushed a function\n");
    printf("Going to block while read from stdin\n");
    n=read(0,buff,100);
    #ifdef A
    pthread_testcancel();
    #endif
    pthread_cleanup_pop(0);
    return NULL ;
    }

    int main(){
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_create(&stid,&attr,sstart,NULL);
    sleep(3);
    pthread_create(&ftid,&attr,fstart,NULL);
    pthread_join(stid,NULL);
    return 0;
    }

    /tmp/katiyarcc -o HP -lpthread HP.c
    /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread
    /tmp/katiyarcc -DA -o HP -lpthread HP.c
    /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread
    I am in pthread handler

    Thanks in advance

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish:

    From what you've written, if you're doing a blocking read(2) call, and a
    cancellation is posted, it would deliver it and like you said, read(2)
    will return and reflect EINTR in the errno. BUT, if its just executing
    read(2) call, but not blocked, it would depend on whether cancellation
    is delivered to it or not, since it would deliver to it only in certain
    states.

    cancellation is delivered, testcancel will not catch it. Could you
    share the code snippet that you're trying, with us?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish Katiyar
    Sent: Friday, September 15, 2006 11:45 AM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Dennnis/Rohit,

    Thanks for your responsesCould you please explain me how does HPUX
    pthread_cancel works in case of blocking system calls. EgIf i am in
    middle of read system call and get a cancellation signal. read will
    return with EINTR am i right ?and after that cancel signal
    still exists or is said to be deliveredcoz If i do a testcancel
    after that I can still see that signal
    --
    thanks in advance.
    >
    >
    >

    9/13/06, Manish Katiyar <mkatiyar (AT) gmail (DOT) comwrote:

    Hi Dennis,

    Thanks for the responseyes main thread should not be cancelled
    but I see this behaviour when i create a thread alsojust to
    keep the code short I cancelled the main thread.

    "I assume that since you aren't calling any libc functions, there is
    no place where synchronous cancels can be caught."

    I partially agree with this coz as I know libc functions just act as
    additional cancellation points. Even if they are not there and thread
    behaviour is deferred, signal should be delivered to the thread at
    some point and this is what I expect.

    Any other suggestions ?
    >
    >
    >
  • No.3 | | 5870 bytes | |

    Hi Rohit,

    I am testing it on both 11.11 PA and 11.23 PAand on both it doesn't
    work without compiling it with -DAIs there any patch issueI have the
    patch 37418 applied on my 11.23 machine.

    /home/katiyar./a.out

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread
    /home/katiyaruname -a
    HP-UX hpsarpc1 B.11.11 U 9000/800 1579700508 unlimited-user license
    /home/katiyar>

    /tmp/katiyarcc -o HP -lpthread HP.c
    /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread
    /tmp/katiyaruname -a
    HP-UX holmium B.11.23 U 9000/800 1759078586 unlimited-user license

    Thanks in advance

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: I've tried the program on both 11.11(PA) and 11.23 (IA) servers.
    Both the cases, the cleanup handler is called, with and without -DA
    options.

    Also, a small correction to what you'd stated in your mail previously
    and I'd asserted that to be true - when you post the cancellation, the
    thread doesn't return from the cancellation point, the thread is
    terminated thereafter. If there is a registered cleanup handler, the
    termination would be post the action of the handler.

    The output I got on my machines is pasted below:

    $ uname -a
    HP-UX rocket B.11.11 U 9000/800 187494646 unlimited-user license
    $ cc -o a -lpthread a.c
    $ ./a

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread
    I am in pthread handler
    $ cc -DA -o a -lpthread a.c
    $ ./a

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread
    I am in pthread handler

    Are you on 11.11(PA), 11.23 (IA) or 11.0?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish Katiyar
    Sent: Friday, September 15, 2006 3:19 PM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,

    Below is my code snippet and its output
    --

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

    pthread_t stid,ftid;

    void hndlr(void *a){
    int oldstate;
    printf("I am in pthread handler\n");
    return ;
    }
    void *fstart(void *tid){
    printf("Sending cancel signal to another thread \n");
    pthread_cancel(stid);
    return NULL;
    }

    void *sstart(void *tid){
    char buff[100];
    int n;
    pthread_cleanup_push(hndlr,NULL);
    printf("\nI have pushed a function\n");
    printf("Going to block while read from stdin\n");
    n=read(0,buff,100);
    #ifdef A
    pthread_testcancel();
    #endif
    pthread_cleanup_pop(0);
    return NULL ;
    }

    int main(){
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_create(&stid,&attr,sstart,NULL);
    sleep(3);
    pthread_create(&ftid,&attr,fstart,NULL);
    pthread_join(stid,NULL);
    return 0;
    }

    /tmp/katiyarcc -o HP -lpthread HP.c
    /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread
    /tmp/katiyarcc -DA -o HP -lpthread HP.c /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread
    I am in pthread handler

    --
    Thanks in advance
    >
    >
    >

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish:

    From what you've written, if you're doing a blocking read(2) call, and

    a cancellation is posted, it would deliver it and like you said,
    read(2) will return and reflect EINTR in the errno. BUT, if its just
    executing
    read(2) call, but not blocked, it would depend on whether cancellation

    is delivered to it or not, since it would deliver to it only in
    certain states.

    cancellation is delivered, testcancel will not catch it. Could
    you share the code snippet that you're trying, with us?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Friday, September 15, 2006 11:45 AM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Dennnis/Rohit,

    Thanks for your responsesCould you please explain me how does
    HPUX pthread_cancel works in case of blocking system calls. EgIf i
    am in middle of read system call and get a cancellation signal. read
    will return with EINTR am i right ?and after that cancel
    signal still exists or is said to be deliveredcoz If i do a
    testcancel after that I can still see that signal
    --
    thanks in advance.
    >
    >
    >

    9/13/06, Manish Katiyar <mkatiyar (AT) gmail (DOT) comwrote:

    Hi Dennis,

    Thanks for the responseyes main thread should not be cancelled

    but I see this behaviour when i create a thread alsojust to
    keep the code short I cancelled the main thread.

    "I assume that since you aren't calling any libc functions, there is

    no place where synchronous cancels can be caught."

    I partially agree with this coz as I know libc functions just act as

    additional cancellation points. Even if they are not there and
    thread behaviour is deferred, signal should be delivered to the
    thread at some point and this is what I expect.

    Any other suggestions ?
    >
    >
    >
  • No.4 | | 7022 bytes | |

    Hi Rohit,

    Could you identify the reason for the behaviour of the program?Thanks in
    advance

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: Firstly, my apology for a stupid mistake that I made. I'd
    introduced a perror() in the program, and it seems that perror was
    catching the cancel request and not the read(). The behaviour you're
    witnessing is the behaviour on 11.11 and 11.23 too.

    Will respond shortly on why we're witnessing this behaviour. The
    man-page seems to mention that read() "can be" a cancellation point but
    Cancel-Safe and Async-cancel-safe sections do not list read() as an
    interface under either of the categories.

    Will get back.

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish Katiyar
    Sent: Friday, September 15, 2006 5:36 PM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,

    I am testing it on both 11.11 PA and 11.23 PAand on both it
    doesn't work without compiling it with -DAIs there any patch
    issueI have the patch 37418 applied on my 11.23 machine.

    /home/katiyar./a.out

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread
    /home/katiyaruname -a
    HP-UX hpsarpc1 B.11.11 U 9000/800 1579700508 unlimited-user license
    /home/katiyar>
    --
    /tmp/katiyarcc -o HP -lpthread HP.c
    /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread
    /tmp/katiyaruname -a
    HP-UX holmium B.11.23 U 9000/800 1759078586 unlimited-user license
    >
    >
    >

    Thanks in advance

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: I've tried the program on both 11.11(PA) and 11.23 (IA)
    servers.
    Both the cases, the cleanup handler is called, with and without -DA
    options.

    Also, a small correction to what you'd stated in your mail previously
    and I'd asserted that to be true - when you post the cancellation, the

    thread doesn't return from the cancellation point, the thread is
    terminated thereafter. If there is a registered cleanup handler, the
    termination would be post the action of the handler.

    The output I got on my machines is pasted below:

    $ uname -a
    HP-UX rocket B.11.11 U 9000/800 187494646 unlimited-user license $ cc
    -o a -lpthread a.c $ ./a

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread I am in pthread handler $ cc
    -DA -o a -lpthread a.c $ ./a

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread I am in pthread handler

    Are you on 11.11(PA), 11.23 (IA) or 11.0?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Friday, September 15, 2006 3:19 PM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,

    Below is my code snippet and its output
    --

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

    pthread_t stid,ftid;

    void hndlr(void *a){
    int oldstate;
    printf("I am in pthread handler\n");
    return ;
    }
    void *fstart(void *tid){
    printf("Sending cancel signal to another thread \n");
    pthread_cancel(stid);
    return NULL;
    }

    void *sstart(void *tid){
    char buff[100];
    int n;
    pthread_cleanup_push(hndlr,NULL);
    printf("\nI have pushed a function\n");
    printf("Going to block while read from stdin\n");
    n=read(0,buff,100);
    #ifdef A
    pthread_testcancel();
    #endif
    pthread_cleanup_pop(0);
    return NULL ;
    }

    int main(){
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_create(&stid,&attr,sstart,NULL);
    sleep(3);
    pthread_create(&ftid,&attr,fstart,NULL);
    pthread_join(stid,NULL);
    return 0;
    }

    /tmp/katiyarcc -o HP -lpthread HP.c
    /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread /tmp/katiyarcc -DA -o HP
    -lpthread HP.c /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread I am in pthread handler

    --
    Thanks in advance
    >
    >
    >

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish:

    From what you've written, if you're doing a blocking read(2) call,
    and

    a cancellation is posted, it would deliver it and like you said,
    read(2) will return and reflect EINTR in the errno. BUT, if its just

    executing
    read(2) call, but not blocked, it would depend on whether
    cancellation

    is delivered to it or not, since it would deliver to it only in
    certain states.

    cancellation is delivered, testcancel will not catch it. Could
    you share the code snippet that you're trying, with us?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Friday, September 15, 2006 11:45 AM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Dennnis/Rohit,

    Thanks for your responsesCould you please explain me how does
    HPUX pthread_cancel works in case of blocking system calls. EgIf
    i am in middle of read system call and get a cancellation signal.
    read will return with EINTR am i right ?and after that
    cancel signal still exists or is said to be deliveredcoz If i

    do a testcancel after that I can still see that signal
    --
    thanks in advance.
    >
    >
    >

    9/13/06, Manish Katiyar <mkatiyar (AT) gmail (DOT) comwrote:

    Hi Dennis,

    Thanks for the responseyes main thread should not be
    cancelled

    but I see this behaviour when i create a thread alsojust to

    keep the code short I cancelled the main thread.

    "I assume that since you aren't calling any libc functions, there
    is

    no place where synchronous cancels can be caught."

    I partially agree with this coz as I know libc functions just act
    as

    additional cancellation points. Even if they are not there and
    thread behaviour is deferred, signal should be delivered to the
    thread at some point and this is what I expect.

    Any other suggestions ?
    >
    >
    >
  • No.5 | | 7615 bytes | |

    Thanks a lot Rohit for your time and advices.

    9/18/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: I got involved with something else. Please gimme sometime. I'll
    reply today, certainly.

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish Katiyar
    Sent: Monday, September 18, 2006 3:06 PM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,

    Could you identify the reason for the behaviour of the
    program?Thanks in advance

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: Firstly, my apology for a stupid mistake that I made. I'd
    introduced a perror() in the program, and it seems that perror was
    catching the cancel request and not the read(). The behaviour you're
    witnessing is the behaviour on 11.11 and 11.23 too.

    Will respond shortly on why we're witnessing this behaviour. The
    man-page seems to mention that read() "can be" a cancellation point
    but Cancel-Safe and Async-cancel-safe sections do not list read() as
    an interface under either of the categories.

    Will get back.

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Friday, September 15, 2006 5:36 PM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,

    I am testing it on both 11.11 PA and 11.23 PAand on both it
    doesn't work without compiling it with -DAIs there any patch
    issueI have the patch 37418 applied on my 11.23 machine.

    /home/katiyar./a.out

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread /home/katiyaruname -a HP-UX
    hpsarpc1 B.11.11 U 9000/800 1579700508 unlimited-user license
    /home/katiyar>
    --
    /tmp/katiyarcc -o HP -lpthread HP.c
    /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread /tmp/katiyaruname -a HP-UX
    holmium B.11.23 U 9000/800 1759078586 unlimited-user license
    >
    >
    >

    Thanks in advance

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: I've tried the program on both 11.11(PA) and 11.23 (IA)
    servers.
    Both the cases, the cleanup handler is called, with and without -DA
    options.

    Also, a small correction to what you'd stated in your mail
    previously and I'd asserted that to be true - when you post the
    cancellation, the

    thread doesn't return from the cancellation point, the thread is
    terminated thereafter. If there is a registered cleanup handler, the

    termination would be post the action of the handler.

    The output I got on my machines is pasted below:

    $ uname -a
    HP-UX rocket B.11.11 U 9000/800 187494646 unlimited-user license $
    cc -o a -lpthread a.c $ ./a

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread I am in pthread handler $ cc -DA -o a -lpthread a.c $

    ./a

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread I am in pthread handler

    Are you on 11.11(PA), 11.23 (IA) or 11.0?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Friday, September 15, 2006 3:19 PM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,

    Below is my code snippet and its output
    --

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

    pthread_t stid,ftid;

    void hndlr(void *a){
    int oldstate;
    printf("I am in pthread handler\n");
    return ;
    }
    void *fstart(void *tid){
    printf("Sending cancel signal to another thread \n");
    pthread_cancel(stid);
    return NULL;
    }

    void *sstart(void *tid){
    char buff[100];
    int n;
    pthread_cleanup_push(hndlr,NULL);
    printf("\nI have pushed a function\n");
    printf("Going to block while read from stdin\n");
    n=read(0,buff,100);
    #ifdef A
    pthread_testcancel();
    #endif
    pthread_cleanup_pop(0);
    return NULL ;
    }

    int main(){
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_create(&stid,&attr,sstart,NULL);
    sleep(3);
    pthread_create(&ftid,&attr,fstart,NULL);
    pthread_join(stid,NULL);
    return 0;
    }

    /tmp/katiyarcc -o HP -lpthread HP.c /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread /tmp/katiyarcc -DA -o HP -lpthread HP.c
    /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread I am in pthread handler

    --
    Thanks in advance
    >
    >
    >

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish:

    From what you've written, if you're doing a blocking read(2) call,

    and

    a cancellation is posted, it would deliver it and like you said,
    read(2) will return and reflect EINTR in the errno. BUT, if its
    just

    executing
    read(2) call, but not blocked, it would depend on whether
    cancellation

    is delivered to it or not, since it would deliver to it only in
    certain states.

    cancellation is delivered, testcancel will not catch it.
    Could you share the code snippet that you're trying, with us?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Friday, September 15, 2006 11:45 AM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Dennnis/Rohit,

    Thanks for your responsesCould you please explain me how
    does HPUX pthread_cancel works in case of blocking system calls.
    EgIf i am in middle of read system call and get a cancellation
    signal.
    read will return with EINTR am i right ?and after that
    cancel signal still exists or is said to be deliveredcoz If

    i

    do a testcancel after that I can still see that signal
    --
    thanks in advance.
    >
    >
    >

    9/13/06, Manish Katiyar <mkatiyar (AT) gmail (DOT) comwrote:

    Hi Dennis,

    Thanks for the responseyes main thread should not be
    cancelled

    but I see this behaviour when i create a thread alsojust
    to

    keep the code short I cancelled the main thread.

    "I assume that since you aren't calling any libc functions,
    there is

    no place where synchronous cancels can be caught."

    I partially agree with this coz as I know libc functions just
    act as

    additional cancellation points. Even if they are not there and
    thread behaviour is deferred, signal should be delivered to the
    thread at some point and this is what I expect.

    Any other suggestions ?
    >
    >
    >
  • No.6 | | 8001 bytes | |

    Hi Rohit,
    yes me too was getting the same behaviourthat is why I thought
    that probably read call after getting the signal is re-raising
    itprobably someone who is more familiar with internals of read can
    help

    Thanks in advance for any suggestions

    9/18/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: I see that for some reason, the read(2) system call is getting
    restarted instead of being terminated with an EINTR. I tried using a
    non-tty file stream but the behaviour persisted.

    Will get back once I get more info on this. Till then, anyone else?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish Katiyar
    Sent: Monday, September 18, 2006 3:06 PM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,

    Could you identify the reason for the behaviour of the
    program?Thanks in advance

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: Firstly, my apology for a stupid mistake that I made. I'd
    introduced a perror() in the program, and it seems that perror was
    catching the cancel request and not the read(). The behaviour you're
    witnessing is the behaviour on 11.11 and 11.23 too.

    Will respond shortly on why we're witnessing this behaviour. The
    man-page seems to mention that read() "can be" a cancellation point
    but Cancel-Safe and Async-cancel-safe sections do not list read() as
    an interface under either of the categories.

    Will get back.

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Friday, September 15, 2006 5:36 PM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,

    I am testing it on both 11.11 PA and 11.23 PAand on both it
    doesn't work without compiling it with -DAIs there any patch
    issueI have the patch 37418 applied on my 11.23 machine.

    /home/katiyar./a.out

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread /home/katiyaruname -a HP-UX
    hpsarpc1 B.11.11 U 9000/800 1579700508 unlimited-user license
    /home/katiyar>
    --
    /tmp/katiyarcc -o HP -lpthread HP.c
    /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin
    Sending cancel signal to another thread /tmp/katiyaruname -a HP-UX
    holmium B.11.23 U 9000/800 1759078586 unlimited-user license
    >
    >
    >

    Thanks in advance

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: I've tried the program on both 11.11(PA) and 11.23 (IA)
    servers.
    Both the cases, the cleanup handler is called, with and without -DA
    options.

    Also, a small correction to what you'd stated in your mail
    previously and I'd asserted that to be true - when you post the
    cancellation, the

    thread doesn't return from the cancellation point, the thread is
    terminated thereafter. If there is a registered cleanup handler, the

    termination would be post the action of the handler.

    The output I got on my machines is pasted below:

    $ uname -a
    HP-UX rocket B.11.11 U 9000/800 187494646 unlimited-user license $
    cc -o a -lpthread a.c $ ./a

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread I am in pthread handler $ cc -DA -o a -lpthread a.c $

    ./a

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread I am in pthread handler

    Are you on 11.11(PA), 11.23 (IA) or 11.0?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Friday, September 15, 2006 3:19 PM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,

    Below is my code snippet and its output
    --

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

    pthread_t stid,ftid;

    void hndlr(void *a){
    int oldstate;
    printf("I am in pthread handler\n");
    return ;
    }
    void *fstart(void *tid){
    printf("Sending cancel signal to another thread \n");
    pthread_cancel(stid);
    return NULL;
    }

    void *sstart(void *tid){
    char buff[100];
    int n;
    pthread_cleanup_push(hndlr,NULL);
    printf("\nI have pushed a function\n");
    printf("Going to block while read from stdin\n");
    n=read(0,buff,100);
    #ifdef A
    pthread_testcancel();
    #endif
    pthread_cleanup_pop(0);
    return NULL ;
    }

    int main(){
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_create(&stid,&attr,sstart,NULL);
    sleep(3);
    pthread_create(&ftid,&attr,fstart,NULL);
    pthread_join(stid,NULL);
    return 0;
    }

    /tmp/katiyarcc -o HP -lpthread HP.c /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread /tmp/katiyarcc -DA -o HP -lpthread HP.c
    /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread I am in pthread handler

    --
    Thanks in advance
    >
    >
    >

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish:

    From what you've written, if you're doing a blocking read(2) call,

    and

    a cancellation is posted, it would deliver it and like you said,
    read(2) will return and reflect EINTR in the errno. BUT, if its
    just

    executing
    read(2) call, but not blocked, it would depend on whether
    cancellation

    is delivered to it or not, since it would deliver to it only in
    certain states.

    cancellation is delivered, testcancel will not catch it.
    Could you share the code snippet that you're trying, with us?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Friday, September 15, 2006 11:45 AM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Dennnis/Rohit,

    Thanks for your responsesCould you please explain me how
    does HPUX pthread_cancel works in case of blocking system calls.
    EgIf i am in middle of read system call and get a cancellation
    signal.
    read will return with EINTR am i right ?and after that
    cancel signal still exists or is said to be deliveredcoz If

    i

    do a testcancel after that I can still see that signal
    --
    thanks in advance.
    >
    >
    >

    9/13/06, Manish Katiyar <mkatiyar (AT) gmail (DOT) comwrote:

    Hi Dennis,

    Thanks for the responseyes main thread should not be
    cancelled

    but I see this behaviour when i create a thread alsojust
    to

    keep the code short I cancelled the main thread.

    "I assume that since you aren't calling any libc functions,
    there is

    no place where synchronous cancels can be caught."

    I partially agree with this coz as I know libc functions just
    act as

    additional cancellation points. Even if they are not there and
    thread behaviour is deferred, signal should be delivered to the
    thread at some point and this is what I expect.

    Any other suggestions ?
    >
    >
    >
  • No.7 | | 8843 bytes | |

    Thanks Rohit,

    for your efforts. I will open a bug with HP regarding this. Has HP any
    official site as Linux's bugzilla for this ?I could not find any link
    where I can report a bug to HP from google or forums.itrc.hp.com.

    Thanks again.

    9/22/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: The behaviour seems to be a bug in read(2) system call. Could I
    request you to file a bug report on the same.

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish Katiyar
    Sent: Tuesday, September 19, 2006 8:18 AM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,
    yes me too was getting the same behaviourthat is why I thought
    that probably read call after getting the signal is re-raising
    itprobably someone who is more familiar with internals of read
    can help

    Thanks in advance for any suggestions

    9/18/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: I see that for some reason, the read(2) system call is getting

    restarted instead of being terminated with an EINTR. I tried using a
    non-tty file stream but the behaviour persisted.

    Will get back once I get more info on this. Till then, anyone else?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Monday, September 18, 2006 3:06 PM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,

    Could you identify the reason for the behaviour of the
    program?Thanks in advance

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: Firstly, my apology for a stupid mistake that I made. I'd
    introduced a perror() in the program, and it seems that perror was
    catching the cancel request and not the read(). The behaviour you're

    witnessing is the behaviour on 11.11 and 11.23 too.

    Will respond shortly on why we're witnessing this behaviour. The
    man-page seems to mention that read() "can be" a cancellation point
    but Cancel-Safe and Async-cancel-safe sections do not list read() as

    an interface under either of the categories.

    Will get back.

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Friday, September 15, 2006 5:36 PM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,

    I am testing it on both 11.11 PA and 11.23 PAand on both it

    doesn't work without compiling it with -DAIs there any patch
    issueI have the patch 37418 applied on my 11.23 machine.

    /home/katiyar./a.out

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread /home/katiyaruname -a HP-UX
    hpsarpc1 B.11.11 U 9000/800 1579700508 unlimited-user license
    /home/katiyar>
    --
    /tmp/katiyarcc -o HP -lpthread HP.c /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread /tmp/katiyaruname -a HP-UX holmium B.11.23 U
    9000/800 1759078586 unlimited-user license
    >
    >
    >

    Thanks in advance

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish: I've tried the program on both 11.11(PA) and 11.23 (IA)
    servers.
    Both the cases, the cleanup handler is called, with and without
    -DA options.

    Also, a small correction to what you'd stated in your mail
    previously and I'd asserted that to be true - when you post the
    cancellation, the

    thread doesn't return from the cancellation point, the thread is
    terminated thereafter. If there is a registered cleanup handler,
    the

    termination would be post the action of the handler.

    The output I got on my machines is pasted below:

    $ uname -a
    HP-UX rocket B.11.11 U 9000/800 187494646 unlimited-user license $

    cc -o a -lpthread a.c $ ./a

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread I am in pthread handler $ cc -DA -o a -lpthread a.c

    $

    ./a

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread I am in pthread handler

    Are you on 11.11(PA), 11.23 (IA) or 11.0?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Friday, September 15, 2006 3:19 PM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Rohit,

    Below is my code snippet and its output
    --

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

    pthread_t stid,ftid;

    void hndlr(void *a){
    int oldstate;
    printf("I am in pthread handler\n");
    return ;
    }
    void *fstart(void *tid){
    printf("Sending cancel signal to another thread \n");
    pthread_cancel(stid);
    return NULL;
    }

    void *sstart(void *tid){
    char buff[100];
    int n;
    pthread_cleanup_push(hndlr,NULL);
    printf("\nI have pushed a function\n");
    printf("Going to block while read from stdin\n");
    n=read(0,buff,100);
    #ifdef A
    pthread_testcancel();
    #endif
    pthread_cleanup_pop(0);
    return NULL ;
    }

    int main(){
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_create(&stid,&attr,sstart,NULL);
    sleep(3);
    pthread_create(&ftid,&attr,fstart,NULL);
    pthread_join(stid,NULL);
    return 0;
    }

    /tmp/katiyarcc -o HP -lpthread HP.c /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread /tmp/katiyarcc -DA -o HP -lpthread HP.c
    /tmp/katiyar./HP

    I have pushed a function
    Going to block while read from stdin Sending cancel signal to
    another thread I am in pthread handler

    --
    Thanks in advance
    >
    >
    >

    9/15/06, Gupta, Rohit (STSD) <rohit.gupta (AT) hp (DOT) comwrote:

    Manish:

    From what you've written, if you're doing a blocking read(2)
    call,

    and

    a cancellation is posted, it would deliver it and like you said,
    read(2) will return and reflect EINTR in the errno. BUT, if its
    just

    executing
    read(2) call, but not blocked, it would depend on whether
    cancellation

    is delivered to it or not, since it would deliver to it only in
    certain states.

    cancellation is delivered, testcancel will not catch it.
    Could you share the code snippet that you're trying, with us?

    Regards,
    Rohit

    Message
    From: owner-hpux-devtools (AT) cxx (DOT) cup.hp.com
    [mailto:owner-hpux-devtools (AT) cxx (DOT) cup.hp.com] Behalf Manish
    Katiyar
    Sent: Friday, September 15, 2006 11:45 AM
    To: hpux-devtools (AT) cxx (DOT) cup.hp.com
    Subject: Re: HPUX-DEVTLS: pthread_cancel doesn't work

    Hi Dennnis/Rohit,

    Thanks for your responsesCould you please explain me how
    does HPUX pthread_cancel works in case of blocking system calls.
    EgIf i am in middle of read system call and get a
    cancellation
    signal.
    read will return with EINTR am i right ?and after
    that cancel signal still exists or is said to be
    deliveredcoz If

    i

    do a testcancel after that I can still see that signal
    --
    thanks in advance.
    >
    >
    >

    9/13/06, Manish Katiyar <mkatiyar (AT) gmail (DOT) comwrote:

    Hi Dennis,

    Thanks for the responseyes main thread should not be
    cancelled

    but I see this behaviour when i create a thread
    alsojust to

    keep the code short I cancelled the main thread.

    "I assume that since you aren't calling any libc functions,
    there is

    no place where synchronous cancels can be caught."

    I partially agree with this coz as I know libc functions just
    act as

    additional cancellation points. Even if they are not there and

    thread behaviour is deferred, signal should be delivered to
    the thread at some point and this is what I expect.

    Any other suggestions ?
    >
    >
    >

Re: HPUX-DEVTOOLS: pthread_cancel doesn't work


max 4000 letters.
Your nickname that display:
In order to stop the spam: 1 + 0 =
QUESTION ON "Unix"

EMSDN.COM