mutex vs atomic<bool>

Сравним разные варианты реализации блокировок с точки зрения накладных расходов. mutex, ptr, atomic в нескольких вариантах. Рассматриваем случай без контеншена.

https://habr.com/ru/articles/1000192/

#atomic #mutex #futex

mutex vs atomic<bool>

Недавно "орлиный глаз" (то есть я) заметил, что в std::atomic у методов есть wait/notify методы. Я думал, что std::atomic это сугубо user-space примитивы синхронизации, но согласно cppref (да и...

Хабр

""The name sure sounds like “mutex”, and that is where the name comes from: “fast, user space mutex”. But, it isn’t really, it’s a building block for concurrency primitives that ushered in a modern world of concurrent performance […]

t was immediately clear that the futex was a huge improvement in highly concurrent environments. Just in that original paper, their tests with 1000 parallel tasks ran 20-120 times faster than sysv locks..🤯

Needless to say, other common operating systems followed suit, including Windows in 2012 and macOS by 2016.

These days, any good locking primitive is going to be based on a futex. […]""

https://h4x0r.org/futex/

#Linux #LinuxKernel #Kernel #Futex

🎉 Surprise! 🎉 Another poorly disguised #advertisement for a book club that's so riveting even its own authors remain a mystery. 🤔 In a shocking twist, the #futex isn't a magical cure for all #programming woes, and the book is as useful as a unicycling octopus in a synchronized swimming competition. 🐙🚴‍♀️
https://h4x0r.org/futex/ #bookclub #humor #unicyclingoctopus #HackerNews #ngated
Without the futex, it's futile | H4X0R****

Review: It's a history text, not a CS text

Without the futex, it's futile | H4X0R****

Review: It's a history text, not a CS text

Бинарные семафоры на futex через parking_lot_core

Привет, Харб! Сегодня рассмотрим, как реализовать собственный бинарный семафор на основе futex и библиотеки parking_lot_core .

https://habr.com/ru/companies/otus/articles/929146/

#rust #parking_lot_core #parking_lot #futex #AtomicU32 #SpinWait

Бинарные семафоры на futex через parking_lot_core

Привет, Харб! Сегодня рассмотрим, как реализовать собственный бинарный семафор на основе futex и библиотеки parking_lot_core . Зачем семафор, если есть Mutex? Ошибка, которую часто совершают...

Хабр
🌖 Futex 趣味:用 C 打造我自己的互斥鎖 (Mutex)
➤ 從旋轉鎖到 Futex:優化鎖定機制的探索
https://blog.fredrb.com/2025/06/02/futex-fun/
本文探討瞭如何在 Linux 環境下實作一個高效的鎖定機制。作者首先介紹了簡單的旋轉鎖 (spin lock),並指出其高 CPU 佔用率的缺點。接著,深入研究了 Linux 的 Futex 系統呼叫,利用其將等待鎖的線程置於睡眠狀態,而非不斷迴圈檢測,從而大幅降低 CPU 消耗。作者詳細解釋了 Futex 的運作原理、不同情境下的行為,並提供了使用 Futex 實作互斥鎖的具體程式碼,並與旋轉鎖進行效能比較。
+ 寫得真棒!詳細解釋了 Futex 的原理和使用方法,對理解 Linux 核心的鎖定機制非常有幫助。
+ 程式碼很清晰易懂,實際跑了一下,CPU 佔用率果然有明顯改善。
#程式設計 #Linux #同步處理 #Futex
Fun with Futex: building my own mutex in C for funtex

Fun with Futex Implementing an optimized lock in Linux requires some Operating System help. You can only get so far by doing everything in user-land. We are going to take a look how one can implement a simple spin lock in C (just like the spin lock in Go I implemented a while back) and then a slightly more elaborate lock using operating system’s primitives. The idea behind a mutex (mutual exclusion) is straightforward: we want some part of the code to be accessed only by a single thread at a time. If the resource a thread is trying to access (the critical zone) is already being accessed by something else: wait. The trick about implementing them is how you to do wait part!

Fredrb's Blog
Some brave soul decided to reinvent the wheel by building their own #mutex in C, because, apparently, mastering pre-existing solutions just wasn't challenging (or fun) enough. 🤦‍♂️ Instead of taking a nice walk outside, they've chosen to dance with futexes, as if Linux needed more accidental 'optimizations.' 🧐🔧
https://blog.fredrb.com/2025/06/02/futex-fun/ #reinventthewheel #Cprogramming #futex #Linuxoptimization #codinghumor #HackerNews #ngated
Fun with Futex: building my own mutex in C for funtex

Fun with Futex Implementing an optimized lock in Linux requires some Operating System help. You can only get so far by doing everything in user-land. We are going to take a look how one can implement a simple spin lock in C (just like the spin lock in Go I implemented a while back) and then a slightly more elaborate lock using operating system’s primitives. The idea behind a mutex (mutual exclusion) is straightforward: we want some part of the code to be accessed only by a single thread at a time. If the resource a thread is trying to access (the critical zone) is already being accessed by something else: wait. The trick about implementing them is how you to do wait part!

Fredrb's Blog
Fun with Futex: building my own mutex in C for funtex

Fun with Futex Implementing an optimized lock in Linux requires some Operating System help. You can only get so far by doing everything in user-land. We are going to take a look how one can implement a simple spin lock in C (just like the spin lock in Go I implemented a while back) and then a slightly more elaborate lock using operating system’s primitives. The idea behind a mutex (mutual exclusion) is straightforward: we want some part of the code to be accessed only by a single thread at a time. If the resource a thread is trying to access (the critical zone) is already being accessed by something else: wait. The trick about implementing them is how you to do wait part!

Fredrb's Blog

[Перевод] Самые быстрые мьютексы

Cosmopolitan Libc хорошо известна своим « полиглотным жирным бинарным » хаком, который позволяем исполняемым файлам запускаться на шести операционных системах для AMD64/ARM64. Вас может удивить, что при этом она может быть лучше С‑библиотекой для вашего продакшена. Чтобы продемонстрировать это, давайте сравним библиотеку мьютексов Cosmo с другими платформами. Мы напишем простой тест, который создает 30 потоков, увеличивающих одно и то же число 100 000 раз. Это поможет проверить, насколько хорошо реализация мьютексов справляется с задачей при интенсивном использовании.

https://habr.com/ru/companies/beget/articles/848318/

#mutex #futex #c++ #cosmopolitan_libc

Самые быстрые мьютексы

Cosmopolitan Libc хорошо известна своим « полиглотным жирным бинарным » хаком, который позволяем исполняемым файлам запускаться на шести операционных системах для AMD64/ARM64. Вас может...

Хабр
🌗 Linux的新futex API [LWN.net]
➤ Linux的futex API得到改進
https://lwn.net/Articles/940944/
這個新的patch系列展示了futex的未來可能會是什麼樣子。這個系列包括了三個新的系統調用,並提供了一些新的功能,通常使用flags參數。其中一個新標誌是FUTEX2_NUMA,旨在提高NUMA系統的性能。此外,新的系統調用還需要一個標誌值,指示要操作的futex的大小。這項工作應該使開發人員更容易處理常見情況,並有可能在將來支持GNU C庫中的futexes。
+ 這個新的API將使開發人員更容易處理常見情況,並有可能在將來支持GNU C庫中的futexes。
+ 讓用戶空間選擇futex的大小是一個好主意,這意味著嵌入式控制系統應該(最終)能夠具有PI和巨型系統仍然可以有許多同時的futexes。
#Linux #futex #API
A new futex API [LWN.net]