Author image

Thread Pool


A thread pool is a software design pattern that helps programmers achieve concurrency in an optimal way. By maintaining a pool of threads ready to execute at any moment performance is increased since latency is minimized by keeping a set of threads always available; at the ready, instead of frequently starting them up and destroying them because of frequent brief tasks. Thus we avoid short lived threads which break concurrency.

All this because creating and destroying threads takes a longer time than keeping them constantly alive and waiting.

Design

  • there is an array of threads - m_pool
  • there is a FIFO queue of tasks (a Task should be a wrapper for a Callable object) - m_tasks. Task are enqueue()ed into the task queue
  • all threads are started...

Author image

Observer Design Pattern


Observer is an important behavioral software design pattern, that is being extensively utilized in almost every single self-respecting codebase as a means to efficiently communicate between objects in an event-based function. It wouldn't be an understatement to say it is the foundation of event based programming.

In fact, underlying the ubiquitous in network programming, “Model View Controller” (MVC) design pattern, is the observer pattern.

Observers are used in every single game engine - they're known there mostly as “Event dispatchers”.

Alternative terminology for this pattern includes the following: - Subscribe-Publish - Listener-Publisher - Delegate-Model - Sink-Source, where the Subject is the source of events and the Observers are sinks of events

1