多个CPU可以同时写入同一个RAM单元? [英] Can multiple CPUs simultaneously write to the same RAM location?

查看:152
本文介绍了多个CPU可以同时写入同一个RAM单元?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是机器字的大小(或更小)写入序列化?只需要一个本地运算code复制登记内容到RAM中。

Are machine word size (or smaller) writes serialized? Only one native opcode is needed to copy register content to RAM.

推荐答案

将数据写入RAM是原子。如果两个CPU试图在同一时间写入到相同的位置,所述存储器控制器将决定某些为了使写入。当一个CPU写入内存,其他的CPU将停止尽可能多的周期根据需要,直到第一个写操作完成;那么它会覆盖它的价值。这就是所谓的有竞争条件

Writing data to RAM is atomic. If two CPUs try to write to the same location at the same time, the memory controller will decide on some order for the writes. While one CPU is writing to memory, the other CPU will stall for as many cycles as necessary until the first write is completed; then it will overwrite its value. This is what's known as a race condition.

写道,比本地字大小小不是原子 - 在这种情况下,CPU必须读取旧的内存值到寄存器,写入新的字节到寄存器,然后写新的值回内存

Writes that are smaller than the native word size are not atomic -- in that case, the CPU must read the old memory value into a register, write the new bytes into the register, and then write that new value back to memory.

您永远不应该有code取决于此 - 如果你有试图同时写入同一个存储单元多CPU,你做错了什么。

You should never have code that depends on this -- if you have multiple CPUs that are trying to simultaneously write to the same memory location, you're doing something wrong.

另一个重要的考虑是高速缓存一致性的问题。每个CPU都有自己的缓存。如果CPU将数据写入高速缓存,其它CPU必须意识到的更改数据的价值,如果他们想读它。

Another important consideration is the cache coherency problem. Each CPU has its own cache. If a CPU writes data to its cache, the other CPUs need to be made aware of the change to that data value if they want to read it.

这篇关于多个CPU可以同时写入同一个RAM单元?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆