简体   繁体   中英

Akka.Net and cache coherence

I am trying to wrap my head around how akka.net concurrency handles cache coherence. Let say I have an Actor that stores some state as a instance field, I understand that only one message is handled at a time. But each message might be processed by a different thread from the thread pool, possibly on a different core/socket. How is akka.net ensuring that different thread sees all changes made to the state field?

A somewhat similar discussion regarding akka https://www.lightbend.com/blog/akka-and-the-java-memory-model , but I am not sure the cache coherence question was properly answered (see last comment).

In terms of cache coherence - the actor's state is only ever read on a single thread at a time (whichever thread is processing the actor's mailbox) and typically that actor is going to process up to 30 messages at a time before yielding the thread to another actor. It's similar to how quantums work in the normal Windows / Linux scheduler.

Therefore, you can view the updates to an actor's memory as transactional - there's no way for two processors to access an actor's memory at the same time since it's private and accessible by only a single thread at a given time. As a result of this cache coherency isn't an issue to begin with because the actor model forces a linearizable history of reads and writes to the state.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM