#mutexes

Felix Palmen :freebsd: :c64:zirias@bsd.cafe
2025-06-11

This redesign of #poser (for #swad) to offer a "multi-reactor" (with multiple #threads running each their own event loop) starts to give me severe headaches.

There is *still* a very rare data #race in the #lockfree #queue. I *think* I can spot it in the pseudo code from the paper I used[1], see screenshot. Have a look at lines E7 and E8. Suppose the thread executing this is suspended after E7 for a "very long time". Now, some dequeue operation from some other thread will eventually dequeue whatever "Q->Tail" was pointing to, and then free it after consumption. Our poor thread resumes, checks the pointer already read in E6 for NULL successfully, and then tries a CAS on tail->next in E9, which is unfortunately inside an object that doesn't exist any more .... If the CAS succeeds because at this memory location happens to be "zero" bytes, we corrupted some random other object that might now reside there. 🤯

Please tell me whether I have an error in my thinking here. Can it be ....? 🤔

Meanwhile, after fixing and improving lots of things, I checked the alternative implementation using #mutexes again, and surprise: Although it's still a bit slower, the difference is now very very small. And it has the clear advantage that it never crashes. 🙈 I'm seriously considering to drop all the lock-free #atomics stuff again and just go with mutexes.

[1] dl.acm.org/doi/10.1145/248052.

Pseudo-code of a lockfree enqueue operation
Ponder Stibbons 🇧🇷🇩🇪blackcoffeerider@social.saarland
2022-12-30

In the 2023's first meeting my answer to the question "what did you guys do in your holidays" will be:
"I wanted to build a small #midi #tui app in #rustlang and fell down the #sidetracking #rabbithole : At the end i implemented MPMC Version of "FIZZBUZZ" and took a deepdive in #threads #channels #boxes #mutexes - unfortunately I didn't get into #macros and all the other good #rust stuff that i still don't understand..."

I always tend to get weird looks in these meetings ...
 Â¯\_(ツ)_/¯

heise online (inoffiziell)heiseonline@squeet.me
2021-03-30
Welche Mechanismen stellt das Pico-SDK für die parallele Abarbeitung verschiedener Aufgaben durch Threads bereit und wie können sie Entwickler einsetzen?

Der vorliegende Beitrag erläutert, welche Mechanismen das Pico-SDK für die parallele Abarbeitung verschiedener Aufgaben durch Threads bereitstellt und wie sie Entwickler einsetzen können.
Des Prozessors Kern – Parallelisierung auf dem Raspberry Pi Pico mit C und C++
2021-01-13

- Readers–writer locks are usually constructed on top of #mutexes and condition variables, or on top of #semaphores.

Rust Languagerustlang@apoil.org
2018-03-05

RT @KevinHoffman: Here's a gist of the code for my latest #rustlang blog post on #threading with #channels and #mutexes : t.co/SGWt… source: twitter.com/rustlang/status/97

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst