dnsjit.core.thread(3)

πŸ“¦
version 1.5.1 Β· 5 versions
, in epel 10, epel 9, fedora 43, fedora 44, ubuntu resolute, ubuntu stonking

πŸ’– dnsjit.core.thread β€” POSIX thread with separate Lua state πŸ’–

okay bestie, welcome to dnsjit.core.thread(3) from the Library Functions Manual πŸŽ€ this one is lowkey iconic: it's a whole POSIX thread with its own Lua state. separate vibes, separate brain, same process. let's get into it ✨


✨ SYNOPSIS ✨

  local thr = require("dnsjit.core.thread").new()
  thr:start(function(thr)
      print("Hello from thread")
      print("got:", thr:pop(), " = ", thr:pop(3))
  end)
  thr:push("value from main", 1, 2, 3)
  thr:stop()

🌸 DESCRIPTION 🌸

So here's the tea: you spin up a brand new POSIX thread, and it gets its own Lua state. Completely its own. No sharing, no crossover, no messy entanglement πŸ’…

Sharable objects can travel over to the thread by pushing them and poping them off the thread stack β€” it's giving very "passing notes in class" energy, except the notes are objects 🫢

⚠️ okay important, listen: the Thread object and any other objects passed to the thread need to be kept alive for as long as the thread is running. no cap. keep them alive or things get weird 😭

🧚 Functions

Thread.new()

Create a new Thread object. fresh, sparkly, ready to go ✨

Thread:log()

Return the Log object so you can control logging for this instance or this module. yep, it's your little logging remote control πŸ“‹

Thread:start(func)

Start the thread and run the given func in a separate Lua state. the first argument handed to that function is the Thread object that created it. returns 0 on success πŸŽ‰

Thread:stop()

Wait for the thread to return. returns 0 on success πŸ›‘

Thread:push(...)

Push string(s), number(s), or sharable object(s) onto the thread stack so they can be picked back up inside the thread with pop(). strings and numbers get copied, but the sharable object(s) need to be kept alive as long as the thread is running β€” yes, again, this is the rule, iykyk πŸ‘‘

Thread:pop(num)

Pop value(s) off the thread stack. should only be called from inside the thread, bestie, don't try it from outside πŸ™ˆ If num isn't given, then exactly one value gets poped. Returns nil if there are no values left on the stack.


πŸ‘€ SEE ALSO πŸ‘€


πŸ‘‘ AUTHORS and CONTRIBUTORS πŸ‘‘

Jerry LundstrΓΆm (DNS-OARC), TomΓ‘Ε‘ KΕ™Γ­ΕΎek (CZ.NIC), Petr Ε paček (ISC)

Maintained by DNS-OARC

https://www.dns-oarc.net/

πŸ’€ BUGS πŸ’€

Got issues? Got feature requests? Please use:

https://codeberg.org/DNS-OARC/dnsjit/issues

Got questions? Need help? Please use:

admin@dns-oarc.net

and that's the whole page, bestie 🫢 this was dnsjit.core.thread(3) β€” dnsjit version 1.5.1, dropped as part of the dnsjit manual set. slay, go forth and thread responsibly πŸ’–βœ¨πŸŽ€