Chinaunix首页 | 论坛 | 博客
  • 博客访问: 215583
  • 博文数量: 89
  • 博客积分: 2531
  • 博客等级: 少校
  • 技术积分: 830
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-19 10:10
文章分类
文章存档

2011年(6)

2010年(26)

2009年(35)

2008年(22)

我的朋友
最近访客

分类: LINUX

2009-12-12 13:52:42

Robert Love在他的《Linux system programming》里对这些概念的阐述对于理解他们很有帮助
Unix systems use the terms synchronized, nonsynchronized, synchronous, and asyn-
chronous freely, without much regard to the fact that they are confusing—in English,
the differences between “synchronous” and “synchronized” do not amount to much!
A synchronous write operation does not return until the written data is—at least—
stored in the kernel’s buffer cache. A synchronous read operation does not return
until the read data is stored in the user-space buffer provided by the application. On
the other side of the coin, an asynchronous write operation may return before the
data even leaves user space; an asynchronous read operation may return before the
read data is available. That is, the operations may only be queued for later. Of
course, in this case, some mechanism must exist for determining when the operation
has actually completed, and with what level of success.
A synchronized operation is more restrictive and safer than a merely synchronous
operation. A synchronized write operation flushes the data to disk, ensuring that the
on-disk data is always synchronized vis-à-vis the corresponding kernel buffers. A
synchronized read operation always returns the most up-to-date copy of the data,
presumably from the disk.
In sum, the terms synchronous and asynchronous refer to whether I/O operations
wait for some event (e.g., storage of the data) before returning. The terms synchro-
nized and nonsynchronized, meanwhile, specify exactly what event must occur (e.g.,
writing the data to disk).
Normally, Unix write operations are synchronous and nonsynchronized; read opera-
tions are synchronous and synchronized.* For write operations, every combination of
these characteristics is possible, as Table 4-1 illustrates.
                Synchronized                                    Nonsynchronized
Synchronous    Write operations do not return until the data    Write operations do not return until
               is flushed to disk. This is the behavior if      the data is stored in kernel buffers. This
               O_SYNC is specified during file open.            is the usual behavior.

Asynchronous   Write operations return as soon as the request   Write operations return as soon as the
               is queued. Once thewrite operation ultimately    request is queued. Once the write oper-
               executes, the data is guaranteed to be on disk.  ation ultimately executes, the data is
                                       guaranteed to at least be stored in
                                                                kernel buffers.
Read operations are always synchronized, as reading stale data makes little sense
Such operations can be either synchronous or asynchronous, however, as illustrate
in Table 4-2.
                Synchronized
Synchronous   Read operations do not return until the data,which is up-               to-date, is stored in the provided buffer (this is                       the usual behavior).
Asynchronous  Read operations return as soon as the request is queued,                 but when the read operation ultimately executes,
阅读(539) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~