In C you might be able to use AIO to do IO in the background without hanging if the IO takes a while, and without the unnecessary creation of threads.
But is there a way I can put a callback function, or manually wait for the AIO operation to end (i.e., like pthread_join()
), besides busy waiting like so?
// Start async operation
// Do work
while (aio_error(some_aiocb) == EINPROGRESS);
// Check if async operation succeeded, etc.
The product I work on is a high-performance messaging system. One of its components is a high-speed message storage. It uses aio_suspend()
to wait for one or more async operations to complete. It supports a timeout. It works well for us.
I have read that there is another method using an "undocumented" function io_set_eventfd()
that lets you use epoll. Here's some unofficial doc that I found. But I have not tried it, so cannot give any guidance.