Concurrency

Concurrency is an ability of the program to execute its control sequence out-of-order or in partial order. This will inevitably cause Race Condition# due to the possible simultaneous access to the same resource. The security might not be sufficient to guard the shared memory from being exploited by an intruder.

That being said, designing a program with concurrency in mind will lead to a smoother workflow, cleaner architecture, clearer interface, and better performance, and allow more rooms for scaling and performance optimisation. The Pragmatic Programmer We can get rid of time or order dependencies by inspecting whether there are tasks or actions that could be happened in parallel with the help of tools such as UML activity diagram. Thinking it in a linear order instead will definitely result in a temporal coupling, that is, coupling in time, where tick must happen before tock.

Hungry consumer model, advocated by Hunt et al., emphasises the use of services: independent, concurrent objects encapsulated behind well-defined consistent interfaces, instead of favouring a central scheduler among consumers#. In this way, they will consume tasks from a work queue without bothering others’ business, and if they finished, they will grab some more from the queue. Let’s say that a consumer task get bogged down because of large input data, others will just pick up the slack. It allows every consumer to proceed data in their own pace.

However, such a design mindset will require all objects in the program to be in a valid state at all time, at least when being called. Make sure that the constructor leaves the object in an initialised state by adhering to some principle such as C++ Rule of Thumb.

Always look for a parallelism solution such as in #this example.

Links to this page
  • constexpr

    It is essentially the same with declaring a const variable that is the variable should not be change in either compile time or runtime. This make the variable avoid all #downside of concurrency.

  • Persistence Programming

    The author reviewed the functionalities of a database and its practicalities: store data values into raw bits which can be read by both programming languages and database, key-value mapping, efficient key sorting for iteration and querying, efficient key lookup with hash tables (unsorted data) or balanced trees (for sorted data) and allow concurrent access# (which emphasises heavily on data atomicity, isolation, consistency and durability).

  • Named Pipe (FIFO)

    FIFO is a #Pipe that have names and directory link. This extends its availability to other processes that are not necessarily related to each other to establish an #Interprocess Communication (IPC) channel between them. Although the blocking on read and write when the queue is empty or full is the default, we can specify it to be non-blocking (flag O_NONBLOCK or O_NDELAY) which doesn’t wait for data or processes. Non-blocking read and write in FIFO also allow Concurrent writing. Atomic write is guaranteed up to 4096 bytes.

  • Multithreading Management

    Multithreading becomes important as the number of core for the processor increases. This allows the possibility of parallelism and concurrency# along with their limitation# and short comings# with the utilisation of threads#. 202201301240# is one of the thinking model hinting on a better parallel and/or concurrency programming.

  • Differences between Parallelism and Concurrency

    In a typical Chinese family, we share dishes such as vegetables, porks, soup etc. in the same table. Even though we happen to hold our own chopsticks and rice, we do share the same dishes. This is call 202202011815#.

#multithreading