指令中的lock前缀的问题
1,对于单处理器系统而言,lock锁住了单条指令的访问,那这有意义吗?单条指令肯定是原子的? 是因为外围设备可以通过DMA方式访问总线,从而在单条指令执行期间修改内存?
2,对于多处理器而言,intel用户手册上说,lock并不会在总线上发出lock信号,而只是依靠高速缓存一致性机制来保证原子性,这就更不懂了:
比如,处理器A的缓存cacheA和处理器B的缓存cacheB,两个缓存对同一个内存区域C进行了缓存,A对A的缓存C作读-修改-写操作, 当A执行完读操作并且修改时,B对C的缓存做写操作,那麽当A回写时缓存不就失效了? 怎麽能保证原子性呢?
还有,若外围设备通过DMA方式访问同一块内存区域呢?
关于cache的lock而言,intel手册上有如下论述:
If a memory access is cacheable and affects only a single cache line, a cache lock is invoked and the system bus and the actual memory location in system memory are not locked during the operation. Here, other Pentium 4, Intel Xeon, or P6 family processors on the bus write-back any modified data and invalidate their caches as necessary to maintain system memory coherency.
不懂啊,其余的处理器将"回写"数据并且使缓存失效, 这里的"回写"指什麽? 将数据从高速缓存写进内存?那麽加锁的处理器的缓存不就失效了?
对于加了lock的高速缓存而言与没加的有什麽区别? 根据手册上的好像没任何区别?