Can buffer passed to io_prep_pwrite/io_submit be reused before io_getevents is called?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have an application where I will call io_prep_pwrite and io_submit in a loop, each time passing the same buffer to io_prep_pwrite, but with different contents.

Then after a certain number of loops, I will call io_getevents before going on to the next file.  

Is this safe to do, or is there a race condition between the buffer being written to file and being reused for the next call to io_prep_pwrite?

Below is some code to illustrate my question (absent any error handling).

Thanks for any input you can provide.

Scott

int main() {
	struct iocb iocb;
	struct iocb * iocbs[1];
	iocbs[0] = &iocb;
	
	int fd = open("/tmp/test", O_WRONLY | O_CREAT);

	io_context_t ctx;
	memset(&ctx, 0, sizeof(ctx));
	io_setup(10, &ctx);

	char msg [128];
          int loopCnt = 0;
	int fileOffset = 0;
	
      	for (; loopCnt < 10; ++loopCnt) {
		int len = snprintf(msg, sizeof(msg), "message number %d\n", loopCnt);
		
		io_prep_pwrite(&iocb, fd, (void *)msg, len, fileOffset);
		fileOffset += len;
			
		io_submit(ctx, 1, iocbs);
	}

	struct io_event events[10];
	io_getevents(ctx, 10, 10, events, NULL);
	close(fd);
	io_destroy(ctx);

	return 0;
}

��.n��������+%������w��{.n�������^n�r������&��z�ޗ�zf���h���~����������_��+v���)ߣ�

[Index of Archives]     [Linux Kernel]     [Linux SCSI]     [Linux IDE]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux