This is the 11th day of my participation in the August Text Challenge.

Concurrency model

  • Concurrent systems can be implemented using different concurrency models that specify how system threads complete tasks. Different concurrent systems split tasks in different ways, and threads communicate and collaborate in different ways.

Similarity of concurrent model to distributed system

  • Concurrent systems have certain similarities with distributed systems. In a concurrent system, different threads communicate with each other. In a distributed system, different processes communicate with each other.
  • Of course, distributed systems face challenges such as network failures and server outages. The concurrent system will face problems such as CPU, network card and disk failure.
  • The threading work model in concurrent systems is similar to the load balancing model in distributed systems.

Shared and separated states

  • An important aspect of the concurrency model is whether components and threads are designed to share state or have separate states that are never shared between threads.
  • Shared state means that different threads of the system will share some state between them. State refers to some data, usually one or more objects. When in the shared state, there can be contention and deadlocks.

  • Detached state means that there is no shared state between different threads. If two threads are to communicate, either immutable objects are exchanged between them or a copy of the object is sent.

  • Using a separate state-concurrency design can often make some parts of your code easier to implement and reason about, because you know that only one thread will write to a given object. You don’t have to worry about concurrent access to this object. However, you may have to think more carefully about the big picture application design to use separate state concurrency. But I think it’s worth it. I personally prefer separate state concurrent design.

Several common concurrency models

There are three common concurrency models:

  • Parallel worker concurrency model
  • Pipelined concurrency model
  • Functional parallel concurrency model

The details of the three models will be discussed in detail in subsequent articles.

Afterword.

  • How many events through the ages? Leisurely. The Yangtze River is still rolling.