Felix Palmen :freebsd: :c64:<p>Today, I implemented the <a href="https://mastodon.bsd.cafe/tags/async" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>async</span></a> / <a href="https://mastodon.bsd.cafe/tags/await" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>await</span></a> pattern (as known from <a href="https://mastodon.bsd.cafe/tags/csharp" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>csharp</span></a> and meanwhile quite some other languages) ...</p><p>... in good old <a href="https://mastodon.bsd.cafe/tags/C" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>C</span></a>! 😎 </p><p>Well, at least sort of.</p><p>* It requires some standard library support, namely <a href="https://mastodon.bsd.cafe/tags/POSIX" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>POSIX</span></a> user context switching with <a href="https://mastodon.bsd.cafe/tags/getcontext" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>getcontext</span></a> and friends, which was deprecated in POSIX-1.2008. But it's still available on many systems, including <a href="https://mastodon.bsd.cafe/tags/FreeBSD" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>FreeBSD</span></a>, <a href="https://mastodon.bsd.cafe/tags/NetBSD" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>NetBSD</span></a>, <a href="https://mastodon.bsd.cafe/tags/Linux" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Linux</span></a> (with <a href="https://mastodon.bsd.cafe/tags/glibc" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>glibc</span></a>). It's NOT available e.g. on <a href="https://mastodon.bsd.cafe/tags/OpenBSD" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>OpenBSD</span></a>, or Linux with some alternative libc.</p><p>* I can't do anything about the basic language syntax, so some boilerplate comes with using it.</p><p>* It has some overhead (room for extra stacks, even extra syscalls as getcontext unfortunately also always saves/restores the signal mask)</p><p>But then ... async/await in C! 🥳 </p><p>Here are the docs:<br><a href="https://zirias.github.io/poser/api/latest/class_p_s_c___async_task.html" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">zirias.github.io/poser/api/lat</span><span class="invisible">est/class_p_s_c___async_task.html</span></a></p><p><a href="https://mastodon.bsd.cafe/tags/C" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>C</span></a> <a href="https://mastodon.bsd.cafe/tags/coding" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>coding</span></a></p>