6 ms·
Please just don't use spinlocks in userland code. It's really not the appropriate mechanism. Your code will look great in your synthetic benchmarks and then it
by haileys 9mo ago
Please just don't use spinlocks in userland code. It's really not the appropriate mechanism.
Your code will look great in your synthetic benchmarks and then it will end up burning CPU for no good reason in the real world.
- nly 9mo agoBurning CPU is preferable in some industries where latency is all that matters.
- masklinn 9mo agoEven outside of such, if your contention is low and critical section short, spinning a few rounds to avoid a syscall is likely to be a gain not just in terms of latencies but also in terms of cycles waste.
- bob1029 9mo agoGaming and high frequency trading are the most obvious examples where this is desirable. If you adjust the multimedia timer to its highest resolution (1ms on windows), sleeping is still a non-starter. Even if the sleep was magically 0ms whenever needed, you still have risk of context switching wrecking your cache and jacking up memory bandwidth utilization.
- imtringued 9mo agoOk, but you do realize that you're now deep in the realm of real time Linux and you're supposed to allocate entire CPU cores to individual processes? What I'm trying to express here is that the spinlock isn't some special tool that you pull out of the toolbox to make something faster and call it a day. It's like a cryogenic superconductor that requires extreme caution to use properly. It's something you avoid doing because it's a pain in the ass.
- gpderetta 9mo agoExclusively allocating a cpu to a specific thread is not exactly rocket science and it is a fairly mundane task.