mutex vs atomic<bool>
Сравним разные варианты реализации блокировок с точки зрения накладных расходов. mutex, ptr, atomic в нескольких вариантах. Рассматриваем случай без контеншена.
mutex vs atomic<bool>
Сравним разные варианты реализации блокировок с точки зрения накладных расходов. mutex, ptr, atomic в нескольких вариантах. Рассматриваем случай без контеншена.
""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. […]""
Without the Futex, It's Futile
#HackerNews #Without #the #Futex #Futile #Futex #Performance #Linux #Kernel #SystemProgramming
Бинарные семафоры на 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
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!
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!
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!
[Перевод] Самые быстрые мьютексы
Cosmopolitan Libc хорошо известна своим « полиглотным жирным бинарным » хаком, который позволяем исполняемым файлам запускаться на шести операционных системах для AMD64/ARM64. Вас может удивить, что при этом она может быть лучше С‑библиотекой для вашего продакшена. Чтобы продемонстрировать это, давайте сравним библиотеку мьютексов Cosmo с другими платформами. Мы напишем простой тест, который создает 30 потоков, увеличивающих одно и то же число 100 000 раз. Это поможет проверить, насколько хорошо реализация мьютексов справляется с задачей при интенсивном использовании.