GEARMAN_WORKER_CREATE(3)

πŸ’– GEARMAN_WORKER_CREATE πŸ’–

okay so bestie, welcome to libgearman land ✨ this is the gearman_worker_create(3) page from the Gearmand Documentation over at http://gearman.info/ β€” three little functions that birth, copy, and yeet your worker structs. it's giving ✨allocator core✨ and honestly? iconic.


✨ NAME ✨

gearman_worker_create β€” Gearmand Documentation, http://gearman.info/


🌸 SYNOPSIS 🌸

first things first, you gotta pull in the header:

#include <libgearman/gearman.h>

gearman_worker_st
*gearman_worker_create(gearman_worker_st *client)

gearman_worker_st
*gearman_worker_clone(gearman_worker_st *client,
const gearman_worker_st *from)

void gearman_worker_free(gearman_worker_st
*client)

and then when you link, don't forget:

Link with -lgearman

no cap, if you skip -lgearman the linker will simply not know her πŸ’€


πŸŽ€ DESCRIPTION πŸŽ€

gearman_worker_create() is the main character here πŸ’… you use it to make a gearman_worker_st structure, and then all the other libgearman(3) client functions use that structure to talk to the server. yes bestie, she's the plug.

so here's the vibe: you either hand her a statically declared gearman_worker_st, or you hand her a NULL. that's it. that's the choice. if you pass a NULL in, then a structure gets allocated for you 🫢

gearman_worker_clone() is basically gearman_worker_create()'s sibling πŸ‘― it does the same thing BUT it also copies over the defaults and the list of servers from the source gearman_worker_st. so like, she comes pre-filled.

  • if you pass a null as the argument for the source you're cloning? that's literally the exact same as calling gearman_worker_create() πŸ™ˆ
  • if the destination argument is NULL, a gearman_worker_st will be allocated for you ✨

then, when you're done and you want to clean up all the memory hanging off a gearman_worker_st structure, you pass it to gearman_worker_free(). and listen β€” gearman_worker_free is the only way to make sure all the memory is deallocated when you finish using the structure. do not freelance this one 😭

⚠️ okay real talk for a sec because this one matters: you may wish to avoid using gearman_worker_create() or gearman_worker_clone() with a stack based allocation, i.e. the first parameter. the most common issues related to ABI safety involve heap allocated structures. so like, heap it. please. for me. 🧚

🌈 RETURN VALUE 🌈

  • gearman_worker_create() returns a pointer to the gearman_worker_st that was created (or initialized). on an allocation failure, it returns NULL πŸ’€
  • gearman_worker_clone() returns a pointer to the gearman_worker_st that was created (or initialized). on an allocation failure, it returns NULL πŸ’€

so yeah. pointer on success, NULL when the allocator says no. check it. always check it. 🫢


πŸ‘‘ HOME πŸ‘‘

to find out more information please check: http://gearman.info/

See also:


πŸ“– Author πŸ“–

Data Differential http://www.datadifferential.com/

2011-2014, Data Differential, http://www.datadifferential.com/


and that's the whole page, bestie, you ate that πŸ“ this was GEARMAN_WORKER_CREATE(3) from the Gearmand manual, version 1.1.21+ds, dated Feb 04, 2026 β€” go forth and allocate responsibly, and remember: gearman_worker_free or it didn't happen πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from