hal_create_thread(3hal)

πŸ“¦
version 2.9.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ hal_create_thread β€” HAL manual, section 3hal ✨

okay bestie, buckle up, we're doing realtime threads today and it's lowkey iconic πŸ§΅πŸ’–


🌸 NAME 🌸

hal_create_thread β€” spin up a HAL thread, bestie. that's the whole job. creating threads, that's her πŸ’…


πŸŽ€ SYNTAX πŸŽ€

int hal_create_thread(const char *name, unsigned long period, int
       uses_fp)

int hal_thread_delete(const char *name)

πŸ¦‹ ARGUMENTS πŸ¦‹

  • name β€” the name of the thread. yeah. that's it. name your baby 🍼
  • period β€” the interval, in nanoseconds, between iterations of the thread. nanoseconds bestie. we are NOT playing around with milliseconds here 😭
  • uses_fp β€” must be nonzero if a function that uses floating-point is gonna get attached to this thread. nonzero. zero is not it. fr fr. if you're doing float math and you pass zero here, that's on you πŸ™ˆ

πŸ’œ DESCRIPTION πŸ’œ

so hal_create_thread establishes a realtime thread, and that thread will execute one or more HAL functions periodically. like a little hamster on a wheel, except the wheel is a hardware timer and the hamster is deterministic 🐹✨

here's the tea though, and you need to hear it:

  • All thread periods are rounded to integer multiples of the hardware timer period. no in-between values, it snaps. periodt.
  • The timer period is based on the first thread created. so whoever goes first sets the vibe for everybody. main character energy, honestly πŸ‘‘
  • Threads must be created in order, from the fastest to the slowest. fastest first, slowest last. do not freestyle this.
  • HAL assigns decreasing priorities to threads that are created later, so creating them from fastest to slowest results in rate monotonic priority scheduling. that's the whole point, that's the slay. fastest thread gets the highest priority, and it just cascades down from there. chef's kiss 🀌

and then hal_delete_thread deletes a previously created thread. bye bestie, you served 🫢

not me pointing out that the description says hal_delete_thread while the SYNOPSIS lists hal_thread_delete β€” I'm just telling you what the page says, I don't make the rules πŸ’€

πŸ”₯ REALTIME CONSIDERATIONS πŸ”₯

call only from realtime init code. NOT from other realtime code. NOT from non-realtime code. just init code. that's the only door, babe πŸšͺ✨


🌈 RETURN VALUE 🌈

returns a HAL status code. classic. πŸ’…


⭐ SEE ALSO ⭐


okay so that's the whole page, no cap. this one came from the LinuxCNC Documentation, dated 2006-10-12, and it lives in the HAL manual as hal_create_thread(3hal). she's been iconic since '06 and she's still iconic now πŸ’–βœ¨πŸŽ€