Urgent.News

What's breaking now, across thousands of outlets.

Tech

Queues Explained with Real Examples from the Linux Kernel

In the last post we looked at the stack, where the last thing in is the first thing out. This time we look at its opposite, the queue. It is just as simple, and the Linux kernel leans on it all the time. Let's start with the idea, write a small one in C, and then see where the kernel uses it. What is a queue? Think of the line at a ticket counter. A new person joins at the back. The person at the…

A queue is similar to a line at a ticket counter, where the first person in line gets their ticket first. In computing, a queue is a data structure with two main operations: enqueue (adding an item to the back) and dequeue (removing an item from the front). Unlike a stack, which serves the most recently added item first, a queue always serves items in the order they arrived, following the first-in, first-out (FIFO) rule.

The article provides a simple implementation of a queue using an array and two pointers (head and tail) to keep track of the front and back of the queue. When the array is full, the tail pointer wraps around to the beginning, creating a circular buffer. The Linux kernel extensively uses queues for various purposes, such as scheduling processes, managing semaphores, and implementing pipes.

The concepts covered in the article can be extended to create more complex data structures, like linked lists, which are also used in the kernel.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

I kept losing good names to the same loop, so I built the tool that breaks it

Naming a project should take an evening. Instead it takes a week. You brainstorm a name you love. The .com is taken. The handle belongs to an account that posted twice in 2019.

  • NamerGuide tool breaks naming loop by providing domain and username availability.
  • Users can save liked names to shortlist without needing an account.
  • Reverse feature offers unregistered brandable domains for purchase.

More from Monday 2 November →