NNG_THREAD_CREATE(3supp)

πŸ“¦ version 1.11, in alpine 3.24

πŸ’… nng_thread_create β€” create thread ✨

okay so bestie, this page is straight from the NNG Reference Manual, and it’s literally about making a thread. it’s giving β€œsmall API, big main-character energy” πŸŽ€


🌸 NAME 🌸

nng_thread_create β€” create thread πŸ’–


✨ SYNOPSIS ✨

#include <nng/nng.h>

typedef struct nng_thread nng_thread;

int nng_thread_create(nng_thread **thrp, void (*func)(void *), void *arg);

πŸ¦‹ DESCRIPTION πŸ¦‹

so nng_thread_create() makes a single thread of execution, and that thread runs func with the argument arg. it starts, like, immediately β€” no waiting around πŸ’… β€” and a pointer to the thread object gets handed back to you in thrp.

the whole point of this little guy is to make writing parallel programs easier. threads made this way are based on whatever underlying threading mechanism the system NNG is running on has. and yes, that may include use of coroutines πŸ‘€

using threads from this function can make it easy to write programs that use simple sequential execution, especially when you’re calling NNG suite functions that would otherwise normally wait synchronously for completion. so you get that β€œone thing at a time” vibe without blocking the whole party 🫢

when you’re done with the thread, you should use nng_thread_destroy() to reap it. and heads up: that function will block waiting for func to return 😭

⚠️ Important: thread objects created by this function may not be real system-level threads capable of doing blocking I/O operations using normal blocking system calls. if you need blocking system calls β€” and no, that doesn’t include APIs provided by the NNG library itself, of course β€” then you should create real OS-specific threads instead, like with pthread_create() or similar functions. no cap.
⚠️ Important: thread objects created by this function cannot be passed to any system threading functions. periodt.
🧚 Tip: the system may impose limits on how many threads you can create. typically, applications should not create more than a dozen of these. if you need greater concurrency or scalability, consider using an asynchronous model with nng_aio structures instead πŸ”₯
πŸŽ€ Tip: threads can be synchronized using mutexes and condition variables. iconic.

🫢 RETURN VALUES 🫢

this function returns 0 on success, and non-zero otherwise. that’s the whole story, bestie πŸ’–


πŸ’€ ERRORS πŸ’€

  • NNG_ENOMEM β€” insufficient free memory exists. not the vibe 😭

🌈 SEE ALSO 🌈


mwah πŸ’– this page is from the NNG Reference Manual, dated 2026-01-13, and its footer tag is NNG_THREAD_CREATE(3supp) β€” slay and goodbye βœ¨πŸ‘‘

πŸ“¦ where this page comes from