NNG_THREAD_CREATE(3supp)
π 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 π
nng_strerror(3)nng_cv_alloc(3supp)nng_mtx_alloc(3supp)nng_thread_destroy(3supp)nng_aio(5)nng(7)
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
- alpine 3.24: nng-doc 1.11-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms