# Concurrent queue in C

DevFeed: [Concurrent queue in C](<https://devfeed.tech/articles/concurrent-queue-in-c-38910.md>)

Original publisher: [Read original article](<https://idea.popcount.org/2012-09-11-concurrent-queue-in-c>)

Author: Marek

Published: 2012-09-10T22:00:00Z

Content type: tutorial

Language: en

Sources: [Marek Majkowski](<https://devfeed.tech/sources/marek-majkowski.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [Concurrent Programming](<https://devfeed.tech/topics/concurrent-programming.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Data structures](<https://devfeed.tech/topics/data-structures.md>), [Algorithms, Complexity](<https://devfeed.tech/topics/algorithms-complexity.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [concurrent](<https://devfeed.tech/tags/concurrent.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [lock-free](<https://devfeed.tech/tags/lock-free.md>), [memory](<https://devfeed.tech/tags/memory.md>), [mutex](<https://devfeed.tech/tags/mutex.md>), [pointers](<https://devfeed.tech/tags/pointers.md>), [queue](<https://devfeed.tech/tags/queue.md>), [thread](<https://devfeed.tech/tags/thread.md>), [threads](<https://devfeed.tech/tags/threads.md>)

## AI overview

This article explains the design and implementation of a thread-safe concurrent queue in C. It compares a mutex-based approach with a lock-free design using CAS, discusses CPU memory ordering and pointer-related memory reclamation problems, and presents a blocking queue implementation using locks.

## Source excerpt

Concurrent queue in C I needed a queue implementation written in C for one of my ever-experimental projects. The complex part was to make it thread-safe - it was going to be used for exchanging data between threads. Usually, I'd just take the doubly linked list implementation from the linux kernel1, wrap it in a mutex and quickly move on to another challenge. This time though, I decided to make sure the queue is as efficient as possible.