[c++-pthreads] cancellation points report failure
Alexander Terekhov
boo at terekhov.de
Wed Dec 24 10:57:35 UTC 2003
Nathan Myers wrote:
[...]
> > 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! */
> > }
*/
if (c == EOF && !feof(f) && errno == ECANCELED)
pthread_exit(PTHREAD_CANCELED);
> > return c;
> > }
>
> I don't understand where you get that. I thought I had made clear
> that I didn't expect any ordinary (correct!) C library code to need
> changes. Since getc_unlocked(f) may always return EOF, so you had
> better be prepared for it. I.e. your original function is of
> questionable correctness.
Huh?
http://www.opengroup.org/onlinepubs/007904975/functions/ungetc.html
"If the value of c equals that of the macro EOF, the operation
shall fail and the input stream shall be left unchanged.
[...]
Upon successful completion, ungetc() shall return the byte
pushed back after conversion. Otherwise, it shall return EOF."
>
> > 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?
> >
> > [1] google.com/groups?selm=slrn8cvkde.mf3.kaz at ashi.FootPrints.net
>
> Buggy code is buggy.
Except that it isn't buggy under the POSIX model where ungetc()
does throw thread cancel exception.
regards,
alexander.
More information about the c++-pthreads
mailing list