インテル® C++ コンパイラー 14.0 ユーザー・リファレンス・ガイド
次に、aio_suspend() 関数を使用して待機操作を実行する例を示します。
int aio_ex_2(HANDLE fd)
{static struct aiocb aio[2];
static struct aiocb *aio_list[2] = {&aio[0], &aio[1]};int i, ret;
/* Data initialization */
IC_AIO_DATA_INIT(aio[0], fd, "rec#1\n", strlen("rec#1\n"), 0)IC_AIO_DATA_INIT(aio[1], fd, "rec#2\n", strlen("rec#2\n"), aio[0].aio_nbytes)/* Asynch-write */
if (aio_write(&aio[0]) == -1) return errno;
if (aio_write(&aio[1]) == -1) return errno;
/* Do some complex computation */
printf("do_compute(1000, 1.123)=%f", do_compute(1000, 1.123));/* do the wait operation using sleep() */
ret = aio_suspend(aio_list, 2, 0);
if (ret == -1) return errno;
return 0;
}/* aio_ex_2 */
実行結果:
#define IC_AIO_DATA_INIT(_aio, _fd, _dat, _len, _off)\
{memset(&_aio, 0, sizeof(_aio)); \_aio.aio_fildes = _fd; \
_aio.aio_buf = _dat; \
_aio.aio_nbytes = _len; \
_aio.aio_offset = _off;}
HANDLE fd = CreateFile("dat",GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL/*|FILE_FLAG_OVERLAPPED*/,
NULL);