Re: [c++-pthreads] cancellation points report failure
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [c++-pthreads] cancellation points report failure



Nathan Myers wrote:
[...]
> If the model works, ...

int peekc(FILE * f) { 
  return ungetc(getc_unlocked(f), f); /* "The ungetc()     */
  /* function is infrequently called relative to the other */
  /* functions/macros so no unlocked variation is needed." */
  /*                                                       */
  /* How fascinating. Well, __fsetlocking() is my friend.  */
}

Both getc_unlocked() and ungetc() are cancelation points. This 
function offers basic exception safety and basic thread safety 
(and it is thread-cancel-safe, of course). Do you really want 
me to change it to something like

int peekc(FILE * f) { 
  int c = ungetc(getc_unlocked(f), f); 
  if (c == EOF && !feof(f) && errno == ECANCELED) {
    /*... ?re-inject cancel request? ... */
    /*... ?re-enable cancel state? ... */
    pthread_testcancel(); /* hurrah! */
  }
  return c;
}

<?>

What if someone[1] has it written as

int peekc(FILE * f) { 
  int c = getc(f); 
  if (c != EOF) 
    ungetc(c, f);
  return c;
}

and cancelation hits at "unchecked" ungetc(), in your model?

regards,
alexander.

[1] google.com/groups?selm=slrn8cvkde.mf3.kaz@xxxxxxxxxxxxxxxxxxx