#C11

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

The #lockfree command #queue in #poser (for #swad) is finally fixed!

The original algorithm from [MS96] works fine *only* if the "free" function has some "magic" in place to defer freeing the object until no thread holds a reference any more ... and that magic is, well, left as an exercise to the reader. 🙈

Doing more research, I found a few suggestions how to do that "magic", including for example #hazardpointers ... but they're known to cause quite some runtime overhead, so not really an option. I decided to implement some "shared object manager" based on the ideas from [WICBS18], which is kind of a "manually triggered garbage collector" in the end. And hey, it works! 🥳
github.com/Zirias/poser/blob/m

[MS96] dl.acm.org/doi/10.1145/248052.
[WICBS18] cs.rochester.edu/u/scott/paper

#coding #c #c11 #atomics

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

I recently took a dive into #C11 #atomics to come up with alternative queue implementations not requiring locking some #mutex.

TBH, I have a hard time understanding the #memory #ordering constraints defined by C11. I mean, I code #assembler on a #mos6502 (for the #c64), so caches, pipelines and all that modern crap is kind of alien rocket science anyways 😆.

But seriously, they try to abstract from what the hardware provides (different kinds of memory barrier instructions, IMHO somewhat easier to understand), so the compiler can pick the appropriate one depending on the target CPU. But wrapping your head around their definition really hurts the brain 🙈.

Yesterday, I found a source telling me that #amd64 (or #x86 in general?) always has strong ordering for reads, so no matter which oderding constraint you put in your atomic_load and friends, the compiler will generate the same code and it will work. Oh boy, how should I ever verify my code works on e.g. aarch64 without owning such hardware?

memory ordering constraints in my lockfree variant of the queue used to schedule commands for a different service thread. Are they correct? 🤔
Felix Palmen :freebsd: :c64:zirias@bsd.cafe
2025-06-04

Hm, is #valgrind's #helgrind useless for code using #atomic operations? Example, it complains about this:

==9505== Possible data race during read of size 4 at 0xADD57F4 by thread #14
==9505== Locks held: none
==9505== at 0x23D0F1: PSC_ThreadPool_cancel (threadpool.c:761)
[....]
==9505== This conflicts with a previous write of size 4 by thread #6
==9505== Locks held: none
==9505== at 0x23CDDE: worker (threadpool.c:373)

so, here's threadpool.c:761:

if ((pthrno = atomic_load_explicit(
&job->pthrno, memory_order_consume)) >= 0)

and here's threadpool.c:373:

atomic_store_explicit(&currentJob->pthrno, -1,
memory_order_release);

Ok, I *think* this should be fine? Do I miss something?

(screenshots for readability ...)

#c #coding #c11 #atomics

valgrind outputthreadpool.c:761threadpool.c:373
Felix Palmen :freebsd: :c64:zirias@bsd.cafe
2025-06-04

I now experimented with different ideas how to implement the #lockfree #queue for multiple producers and multiple consumers. Unsurprisingly, some ideas just didn't work. One deadlocked (okaaay ... so it wasn't lockfree) and I eventually gave up trying to understand why.

The "winner" so far is only "almost lockfree", but at least slightly improves performance. Throughput is the same as with the simple locked variant, but average response times are 10 to 20% quicker (although they deviate stronger for whatever reason). Well, that's committed for now:

github.com/Zirias/poser/commit

#C11 #atomics

Felix Palmen :freebsd: :c64:zirias@bsd.cafe
2025-04-18

Next #swad improvement: Make sure to #wipe #passwords from RAM directly after used. That's more of a #security precaution, because there *should* be no way how an attacker can access a running process' memory, but you never know which bugs surface 🙈.

Unexpectedly, that posed #portability issues. #C11 has #memset_s ... a pretty weird function, but suitable for wiping. It's there on #FreeBSD and on #OpenBSD. Not on #NetBSD though. But NetBSD offers the much saner #C23 function #memset_explicit. Looking at #Linux, there's neither. But there is the (non-standard!) #explicit_bzero 🤯 .. and with glibc, it requires _DEFAULT_SOURCE to be defined as soon as you compile with a C standard version given to the compiler. This function exists on some other systems as well, but there's confusion whether it should be declared in string.h or strings.h. 🤪

Here's the full set of compile-tests I'm now doing, only to find the best way to really erase memory:
github.com/Zirias/swad/blob/ma

And if none of these functions is found, swad uses the "hacky" way that most likely works as well: Access the normal memset function via a volatile pointer.

2025-01-26

This sits beside a yakiniku restaurant in , not far from the final resting place of the Emperor Nintoku. train

cityhillsandsea.com/2022/05/31

Miguel Afonso Caetanoremixtures@tldr.nettime.org
2024-11-15

"Canadians could enjoy the resliency that comes of having a domestic tech and repair sector, and could count on it through pandemics and Trumpian trade-war.

All of that and more could be ours, except for the cowardice and greed of Tony Clement and James Moore and the Harper Tories who voted C-11 into law in 2012.

Everything the "radical extremists" warned them of has come true. It's long past time Canadians tore up anticircumvention law and put the interests of the Canadian public and Canadian tech businesses ahead of the rent-seeking enshittification of American Big Tech.

Until we do that, we can keep on passing all the repair and interop laws we want, but each one will be hamstrung by Moore and Clement's "felony contempt of business model" law, and the contempt it showed for the Canadian people."

pluralistic.net/2024/11/15/rad

#Canada #USA #RightToRepair #Interoperability #C11 #BigTech

Felix Palmen :freebsd: :c64:zirias@bsd.cafe
2024-06-16

@0x1eef Uhh, that's weird. threads.h is a #C11 standard header, So a C11-compliant C environment should ship it. I had no issues on #FreeBSD (clang, base libc) and on #Linux (gcc, glibc) 🤨

Admittedly, C11 threads aren't used much in the wild, everyone uses POSIX threads, and so do I in poser. It could probably be modified not to require threads.h, IIRC I just use it for a "natural" way to declare thread-local storage. Still I doubt my lib is the *only* one to use it, so there should really be some way to have that header on #OpenBSD as well, maybe they have it in some port? 🤔

trendless 🇨🇦 :flag_AB:trendless@zeroes.ca
2024-06-13

This is why the marketing/messaging about legislation doesn't matter -- because the lawyers who will be leveraging it dgaf what was said by others, only what it allows them to argue.

> Our politics is often dominated by debates about deceptive communication, frequently characterized as misinformation or disinformation. For my money, the government’s approach on Bill C-11 provides a paradigm example. Just ask the lawyers at the Ministry of Justice.

🔗 Government Court Filing on Bill C-11: “The Act Does Allow For the Regulation of User-Uploaded Programs on Social Media Services” michaelgeist.ca/2024/06/govern

#BillC11 #C11

रञ्जित (Ranjit Mathew)rmathew
2024-05-21

Some great points, some not so great ones:

“My Favorite C Programming Practices” [2014], Malcolm Inglis (github.com/mcinglis/c-style).

Via HN: news.ycombinator.com/item?id=4

Felix Palmen :freebsd: :c64:zirias@bsd.cafe
2024-05-16

Wow, I was stalled for days now because I couldn't figure out why my queue of outstanding #X11 replies always quickly overflowed.

Turns out one factor was a simple coding error in text rendering test code, leading to repeatedly issuing the same requests 🙈.

But I didn't find that because processing also stalled. Turns out integrating #xcb correctly with your own event loop is somewhat tricky 🤯.

I guess I figured it out now, finally 🥳. And for the first time ever, I found a good use for #C11's _Generic() 😂. Screenshot is lots of debugging output, the batch of confirmed requests on the bottom is from requests uploading #glyphs, and trying to use some #xrender stuff with them. Now for the hard part: My window stays plain white ... 😒

रञ्जित (Ranjit Mathew)rmathew
2024-04-11

Uff! This is a nasty & unexpected in the specification 😰:

“Workarounds For C11 _Generic” [2023], Simon Tatham (chiark.greenend.org.uk/~sgtath).

Via Lobsters: lobste.rs/s/lqx0w5/workarounds

On HN: news.ycombinator.com/item?id=3

2024-03-05

Turns out #Linux moved from C89 to #C11 a couple years back: git.kernel.org/pub/scm/linux/k It's quite surprising; I thought they'x upgrade only if GCC dropped support for C89 :D

(I'm catching up on my Pocket archive, can you tell? BTW I still find #LWN the best source of inspiration for good software engineering. Just read some, and you're guaranteed to experience an urge to roll up your sleeves and go hack on something.)

2024-02-05

Frama-C's new machdep mechanism allows users to more easily create their own machdeps (machine-dependent configuration files). With a #C11-compatible compiler, it's automatic! Check out our new blog post for more details: frama-c.com/2024/01/29/new-mac

(And feel free to ask questions here, we'll try to answer them as best we can.)

Christian Aubry 🇨🇦🇺🇦amicalmant@jasette.facil.services
2023-11-19

@mimo @Carl (2) 27 avril 2023: "La réforme de la Loi sur la radiodiffusion intégrant des plateformes comme Netflix, #YouTube et #Spotify obtient finalement l'aval du Sénat et pourra devenir réalité." Source: Radio-Canada ici.radio-canada.ca/nouvelle/1 #C11

Christian Aubry 🇨🇦🇺🇦amicalmant@jasette.facil.services
2023-11-18

@Carl On avait déjà perdu le droit de partager des lien de nouvelles. Bientôt, on ne pourra plus écouter Spotify sans VPN. Bravo, champions! #C11 👏🥳 noovo.info/nouvelle/ottawa-pub

2023-10-06

Andrew Coyne very clearly articulates why the Canadian goverment's #C11 #LinkTax and #C18 internet #CanCon bills are actively harmful to Canadians and our access to #journalism and the #internet generally. Certainly we have challenges to face on these issues, but a good start would be not making things worse with misguided and heavy-handed regulations

theglobeandmail.com/opinion/ar

#paywall

2023-10-04

Just so we’re clear: literally no part of c-11 is censorship.

No content will be made unavailable. It will remain searchable without restriction, even if more cancon is pushed to the front page.

Fuck, what a dumb argument. Even for righties.

As a general rule: if Elon and Glenn Greenwald agree on something it’s definitely bullshit.

#c11 #cdnpoli #Canada

Michael Geistmgeist@mas.to
2023-09-29

CRTC establishes new registration requirements arising from Bill C-11 for streaming services worldwide, including video and podcasters. Any service - alone or as a group - generating $10M+ in broadcast revenues in Canada must register by November 29, 2023.
twitter.com/CRTCeng/status/170

#C11

2023-08-31

Sadly #c11; #c18; and a #mandatorytariff for #accesscopyright are all about putting Canada in the slow lane on #copyright just like the EU. Let's avoid a permission culture in copyright.

youtube.com/watch?v=INoveo22r4

Client Info

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