qt_loop(3)

πŸ“¦ version 1.22^20251007gitcedb1fc, in fedora 43, fedora 44

πŸ’– qt_loop(3) πŸ’–

okay bestie, welcome to libqthread's cutest little loop situation ✨


🌸 NAME 🌸

qt_loop β€” a simple implementation of a threaded loop πŸ§΅πŸ¦‹


✨ SYNOPSIS ✨

#include <qthread/qloop.h>

void
qt_loop (const size_t start, const size_t stop,
         const qt_loop_f func, void *argptr);

void
qt_loop_step (const size_t start, const size_t stop,
              const size_t stride, const qt_loop_f func, void *argptr);

πŸ’… DESCRIPTION πŸ’…

so these functions give you a simple C implementation of a threaded loop. no cap. 🫢

it's giving mt_loop energy, but like… not with all the convenience and isomorphism that a C++ implementation can hand you. and honestly? that's the tradeoff, and it ate. because what you do get is more portable and more predictable. main character behavior, honestly. πŸ‘‘

the one real difference between the two: qt_loop_step() supports a stride argument, while qt_loop() just assumes a stride of one. that's it. that's the whole tea. 🍡

you can lowkey think of this function as being akin to this code right here:

unsigned int i;
for (i = start; i < stop; i += stride) {
       func(i, i+1, argptr);
}

and here's the part that matters fr fr: a qthread is spawned for every iteration of the above loop. so if start is 50, stop is 100, and stride is 1, there will be 50 qthreads. but if start is 50, stop is 100, and stride is 2, there will be 25 qthreads. the math is mathing. πŸ”₯

now, the func argument must be a function pointer with a qt_loop_f prototype, like this bestie:

void func (size_t start, size_t stop, void *arg);

the return value of this function is ignored πŸ™ˆ. however β€” and this is the important bit β€” qt_loop() will not return until all of the qthreads it spawns have returned. it's not leaving the group chat until everyone's replied. periodt. πŸ’€


🌈 SEE ALSO 🌈


k that's the whole page bestie, go forth and thread responsibly πŸ’œ

libqthread Β· APRIL 2011 Β· qt_loop(3) β€” mwah, ily, bye πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from