Email List: Xaustin-review-lX
[All Lists]

Defect in XSH pthread_detach()

To: yyyyyyyyyyyyyyy@xxxxxxxxxxxxx
Subject: Defect in XSH pthread_detach()
From: yyyyyyyy@xxxxxxxxxx
Date: Wed, 6 Nov 2002 18:46:23 GMT
        Defect report from : Alexander Terekhov , IBM

(Please direct followup comments direct to yyyyyyyyyyyyyy@xxxxxxxxxxxxx)

@ page 1049 line 32951 section pthread_detach() objection 
{alt-detach-2002-11-06}

Problem:

Defect code :  1. Error

The specification says:

32951 The pthread_detach() function shall fail if:
32952 [EINVAL] The implementation has detected that the value specified by 
thread does not
32953 refer to a joinable thread.
32954 [ESRCH] No thread could be found corresponding to that specified by the 
given thread
32955 ID.

"shall fail" is probably wrong here. Illustration: 
<please see also "alt-join-2002-10-22" and "alt-kill-2002-11-06">

lnxmuell:/usr/terekhov # gcc -v
Reading specs from /usr/lib/gcc-lib/s390-suse-linux/2.95.3/specs
gcc version 2.95.3 20010315 (SuSE)
lnxmuell:/usr/terekhov # rpm -q glibc
glibc-2.2.2-26
lnxmuell:/usr/terekhov # gcc -pthread -o detach detach.c
lnxmuell:/usr/terekhov # ldd ./detach
        libpthread.so.0 => /lib/libpthread.so.0 (0x40022000)
        libc.so.6 => /lib/libc.so.6 (0x40038000)
        /lib/ld.so.1 => /lib/ld.so.1 (0x40000000)
lnxmuell:/usr/terekhov # ./detach 0
2nd detach: 22
Guess what... : Invalid argument
lnxmuell:/usr/terekhov # ./detach 1
2nd detach: 3
Guess what... : No such process
lnxmuell:/usr/terekhov # ./detach 1
2nd detach: 22
Guess what... : Invalid argument
lnxmuell:/usr/terekhov # ./detach 0
2nd detach: 22
Guess what... : Invalid argument
lnxmuell:/usr/terekhov # ./detach 1
2nd detach: 3
Guess what... : No such process
lnxmuell:/usr/terekhov # ./detach 1
2nd detach: 3
Guess what... : No such process
lnxmuell:/usr/terekhov # ./detach 1
2nd detach: 3
Guess what... : No such process
lnxmuell:/usr/terekhov # ./detach 100
2nd detach: 3
Guess what... : No such process
lnxmuell:/usr/terekhov # ./detach 0
2nd detach: 22
Guess what... : Invalid argument
lnxmuell:/usr/terekhov # ./detach 1000000
2nd detach: 3
Guess what... : No such process
lnxmuell:/usr/terekhov # ./detach 0
2nd detach: 22
Guess what... : Invalid argument
lnxmuell:/usr/terekhov # cat detach.c

#include <errno.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

void* dummy( void* p ) { return 0; }

int main(int argc, char *argv[]) {
  int status;
  pthread_t thid;
  assert( 2 == argc );
  status = pthread_create( &thid, 0, &dummy, 0 );
  assert( !status );
  status = pthread_detach( thid );
  assert( !status );
  status = atoi(argv[1]);
  if ( status ) usleep( status );
  status = pthread_detach( thid );
  printf( "2nd detach: %d\n", status );
  if ( status ) {
    errno = status;
    perror( "Guess what... " );
  }
  return 0;
}

lnxmuell:/usr/terekhov #


Action:

Replace "shall fail" with "may fail":

32950 ERRORS
32951 The pthread_detach() function may fail if:
32952 [EINVAL] The implementation has detected that the value specified by 
thread does not
32953 refer to a joinable thread.
32954 [ESRCH] No thread could be found corresponding to that specified by the 
given thread
32955 ID.

<Prev in Thread] Current Thread [Next in Thread>
  • Defect in XSH pthread_detach(), terekhov <=