3 ms·
Maybe that’s a case of the wrong design? The index tables shouldn’t need global locks. It gets a little hairy if you need to be able to reallocate or move them
by slashdev 3y ago
Maybe that’s a case of the wrong design? The index tables shouldn’t need global locks. It gets a little hairy if you need to be able to reallocate or move them (I.e grow them) but that happens at most a small number of times and there are ways of only taking the lock if that’s happening.
I’ve implemented this pattern without locks or CAS in C++, and it works just fine.
I’m currently using this pattern in rust (although with fixed size) and it works really well. The best part is it bypasses the borrow checker since an index isn’t a reference. So no compile time lifetimes to worry about. It’s awesome for linked lists, which are otherwise painful in rust. Also it can sometimes allow a linked list with array like cache performance, since the underlying layout is an array.
- Animats 3y ago"it bypasses the borrow checker since an index isn’t a reference" That's a bug, not a feature. The two times I've had go to looking for a bug in the lower levels of Rend3/WGPU (which are 3D graphics libraries), they've involved some index table being corrupted. That's the only time I've needed a debugger.
- slashdev 3y agoLifetimes are managed at runtime, somewhat like Arc, just without the ref counts. If implemented well you get an assertion if you misuse a reference (eg use after free.) I’m fine with the trade off, but yes, it can be a source of difficult bugs.