Spinning around: Please don’t – Common problems with spin locks
1–10 of 66 posts
Re: Spinning around: Please don’t – Common problems with spin locks
#2Re: Spinning around: Please don’t – Common problems with spin locks
#3Re: Spinning around: Please don’t – Common problems with spin locks
#4Sheesh. Can something this complicated ever truly be said to work?
Re: Spinning around: Please don’t – Common problems with spin locks
#5The only time I've manually written my own spin lock was when I had to coordinate between two different threads, one of which was running 16-bit code, so using any library was out of the question, and even relying on syscalls was sketchy because making sure the 16-bit code is in the right state to call a syscall itself is tricky. Although in this case, since I didn't need to care about things like fairness (only two threads are involved), the spinlock core ended up being simple:
"thunk_spin:",
"xchg cx, es:[{in_rv}]",
"test cx, cx",
"jnz thunk_has_data",
"pause",
"jmp thunk_spin",
"thunk_has_data:",Re: Spinning around: Please don’t – Common problems with spin locks
#6Sheesh. Can something this complicated ever truly be said to work?
Re: Spinning around: Please don’t – Common problems with spin locks
#7Sheesh. Can something this complicated ever truly be said to work?
You can limit yourself to the performance of a 1mhz 6502 with no OS if you don't like it. Even MSDos on a 8086 with 640K ram allows for things that require complexity of this type (not spin locks, but the tricks needed to make "terminate stay resident" work are evil in a similar way)
Re: Spinning around: Please don’t – Common problems with spin locks
#8The basic rule of writing your own cross-thread datastructures like mutexes or condition variables is... don't, unless you have very good reason not to. If you're in that rare circumstance where you know the library you're using isn't viable for some reason, then the next best rule is to use your OS's version of a futex as the atomic primitive, since it's going to solve most of the pitfalls for you automatically. The…
Re: Spinning around: Please don’t – Common problems with spin locks
#9Earlier quoted context omitted.
You can limit yourself to the performance of a 1mhz 6502 with no OS if you don't like it. Even MSDos on a 8086 with 640K ram allows for things that require complexity of this type (not spin locks, but the tricks needed to make "terminate stay resident" work are evil in a similar way)
I don't think that's fair. You can go fast, just not more than one task at a time.