Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> All loops must have a fixed upper-bound

Things like spinlocks or CAS (Compare-And-Swap) are elegant and safe solutions for concurrency, and AFAIK you can’t really limit their upper bound. Others in the thread have pointed out that those are more guidelines than rules - still, not sure about this one.



Historically, the right limit for a loop around a spin lock/CAS was related to the effective time cost of a context switch (taking into account both the register save/restore and TLB flush). This is not a fixed number across all hardware but it is knowable upper bound.


That’s an interesting perspective. I‘m not sure I‘d ever be able to act on this outside of some embedded environments - even there, we now have actual OSs and the variance that comes with them.


Context switches on most general purpose OS's are non-preemptible. It's relatively easy to find out what they cost. The TLB hit is application dependent - it depends on the working set (memory use footprint) after the switch. This is not some hard to know thing, certainly not for the purposes of bounding a spinlock.


I suspect multi-threaded programming for spacecraft is frowned upon at NASA.


Not sure about now, but it apparently was allowed when the Mars Pathfinder priority inversion problem happened.


AIUI that involved the scheduler for multiple processes not threads.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: