nerdculture.de is one of the many independent Mastodon servers you can use to participate in the fediverse.
Be excellent to each other, live humanism, no nazis, no hate speech. Not only for nerds, but the domain is somewhat cool. ;) No bots in general. Languages: DE, EN, FR, NL, ES, IT

Administered by:

Server stats:

1.2K
active users

#async

5 posts4 participants2 posts today

Today, I implemented the #async / #await pattern (as known from #csharp and meanwhile quite some other languages) ...

... in good old #C! 😎

Well, at least sort of.

* It requires some standard library support, namely #POSIX user context switching with #getcontext and friends, which was deprecated in POSIX-1.2008. But it's still available on many systems, including #FreeBSD, #NetBSD, #Linux (with #glibc). It's NOT available e.g. on #OpenBSD, or Linux with some alternative libc.

* I can't do anything about the basic language syntax, so some boilerplate comes with using it.

* It has some overhead (room for extra stacks, even extra syscalls as getcontext unfortunately also always saves/restores the signal mask)

But then ... async/await in C! 🥳

Here are the docs:
zirias.github.io/poser/api/lat

zirias.github.ioposer: PSC_AsyncTask Class Reference

I finally eliminated the need for a dedicated #thread controlling the pam helper #process in #swad. 🥳

The building block that was still missing from #poser was a way to await some async I/O task performed on the main thread from a worker thread. So I added a class to allow exactly that. The naive implementation just signals the main thread to carry out the requested task and then waits on a #semaphore for completion, which of course blocks the worker thread.

Turns out we can actually do better, reaching similar functionality like e.g. #async / #await in C#: Release the worker thread to do other jobs while waiting. The key to this is user context switching support like offered by #POSIX-1.2001 #getcontext and friends. Unfortunately it was deprecated in POSIX-1.2008 without an obvious replacement (the docs basically say "use threads", which doesn't work for my scenario), but still lots of systems provide it, e.g. #FreeBSD, #NetBSD, #Linux (with #glibc) ...

The posercore lib now offers both implementations, prefering to use user context switching if available. It comes at a price: Every thread job now needs its private stack space (I allocated 64kiB there for now), and of course the switching takes some time as well, but that's very likely better than leaving a task idle waiting. And there's a restriction, resuming must still happen on the same thread that called the "await", so if this thread is currently busy, we have to wait a little bit longer. I still think it's a very nice solution. 😎

In any case, the code for the PAM credential checker module looks much cleaner now (the await "magic" happens on line 174):
github.com/Zirias/swad/blob/57

Simple Web Authentication Daemon. Contribute to Zirias/swad development by creating an account on GitHub.
GitHubswad/src/bin/swad/cred/pamchecker.c at 57eefe93cdad0df55ebede4bd877d22e7be1a7f8 · Zirias/swadSimple Web Authentication Daemon. Contribute to Zirias/swad development by creating an account on GitHub.

Python friends:

I have a desire to build a small program for testing a piece of hardware I am designing. This program will need to have a REPL so the user can invoke various configuration and test commands while connected to the device, but also asynchronously handle data arriving from that device and displaying it.

Can anyone suggest packages and/or a strategy for doing this?

New Kitten update

🥳 Kitten HTML templates and kitten.Component render functions can now be async.

kitten.small-web.org

This is quite a big one and it took me finally biting the bullet and getting my head around generators in JavaScript to implement properly.

So now you can mix synchronous and asynchronous components as you like and if there are any asynchronous components in your templates they will automatically be awaited (even if you forget to use await) ;)

I’ll write a proper post/tutorial/documentation for it soon but for the time being enjoy the screenshots where a layout template gets the latest three posts from my mock fediverse public timeline service and displays them on the page.

The kitten.Component version also has a refresh button that streams a different three to the page.

For those of you unfamiliar with Kitten, this is all the code in either example. No scaffolding, nothing. Pop either into a file called index.page.js and run kitten in that folder and visit https://localhost to see the example run.

Enjoy!

:kitten:💕

Continued thread

for now, it pops up a scrolling table, based on data loaded by a multi-threaded indexing loop (doing concurrency in #rust is pretty enjoyable! no #async needed, either). lets you edit it (but crashes on backspace, lol). doesn't save it yet. pre-alpha stuff.

How browsers REALLY load Web pages

When browsers load a Web page and its subresources, A LOT happens under the hood. They need to take into account render/parsing blocking resources, use a preload scanner, listen to resource hints (like preload/preconnect), loading modifiers (async/defer/module), fetchpriority, responsive images, and much more. […]

📺 fosdem.org/2025/schedule/event

fosdem.orgFOSDEM 2025 - How browsers REALLY load Web pages
#video#web#browser

Do you want to hear about some different ways to build the #Web? Perhaps you just want to think more cleanly about the boundaries between #Async and #Sync code?

If any/all of these apply to you, or even if you are just a bit "#Rust Curious" then please come along to the next edition of "Rust and Friends" on Thursday 20th March (in less than two weeks).: meetup.com/rust-and-friends/ev

MeetupMarch Talks! (Two), Thu, Mar 20, 2025, 6:30 PM | MeetupIt's time for some talks again! Tonight we’ll be hearing from: * [Chris Stafford](https://www.linkedin.com/in/chris-stafford-72a8562a/) on **Escaping Node and React: Power