Software FIFOs typically are based on a
circular buffer or
list structure. Most software implementations are not
thread safe and require a locking mechanism to ensure the data structure chain is being manipulated by only one thread at a time. In computing environments that support the
pipes-and-filters model for
interprocess communication, a FIFO is another name for a
named pipe.
C++ language example The following code shows a
linked list FIFO
C++ language implementation. In practice, a number of list implementations exist, including popular Unix systems C sys/queue.h macros or the C++
standard library std::list template, avoiding the need for implementing the data structure from scratch. • include • include using namespace std; template class FIFO { struct Node { T value; shared_ptr next = nullptr; Node(T _value): value(_value) {} }; shared_ptr front = nullptr; shared_ptr back = nullptr; public: void enqueue(T _value) { if (front == nullptr) { front = make_shared(_value); back = front; } else { back->next = make_shared(_value); back = back->next; } } T dequeue() { if (front == nullptr) throw underflow_error("Nothing to dequeue"); T value = front->value; front = move(front->next); return value; } }; ==Electronic FIFO==