Bug#123252: aio_cancel does not cancel a blocked aio_read
Hi,
The following code demonstrates what I believe is the same issue as
was originally reported, but does so reading from stdin. Once the
aio_read has begun and blocked, aio_cancel is unable to interrupt
it until some data does arrive to be read.
This means it is not possible to destroy the input buffer for a
read that you no longer care to get (or know you will never get)
since if some data does later arrive, the aio_handler function
will still be called. If none ever does, you'll accrue a 'zombie'
thread for the remaining life of the process. Neither of which
is a great situation... so I do hope we can fix this.
Cheers,
Ron
$ gcc aio.c -o aio -lrt
$ ./aio
aww poo.
/* aio.c */
#include <stdio.h>
#include <unistd.h>
#include <aio.h>
static void aio_handler(union sigval data)
{
printf("aio read\n");
}
int main()
{
struct aiocb aio;
char buf;
aio.aio_fildes = STDIN_FILENO;
aio.aio_offset = 0;
aio.aio_buf = &buf;
aio.aio_nbytes = 1;
aio.aio_reqprio = 0;
aio.aio_sigevent.sigev_notify = SIGEV_THREAD;
aio.aio_sigevent.sigev_notify_function = aio_handler;
aio.aio_sigevent.sigev_notify_attributes = NULL;
aio.aio_sigevent.sigev_value.sival_ptr = NULL;
aio_read( &aio );
sleep(1);
if( aio_cancel( STDIN_FILENO, &aio ) == AIO_NOTCANCELED )
printf("aww poo.\n");
else
printf("woo hoo!\n");
return 0;
}
Reply to: