News for hackers. Stuff that matters.
Re:Zig's new LinkedList API (it's time to learn fieldParentPtr) by bananabiscuit on Monday April 14, 2025 @09:37AM (#43681133)
Do you mean you will likely make an error when implementing a standard textbook linked list? Or that a standard textbook linked list has non-obvious errors in its design? If so, would be curious to learn more.
Re:Zig's new LinkedList API (it's time to learn fieldParentPtr) by simonask on Monday April 14, 2025 @11:28AM (#43682370)
Most programmers can implement a linked list.

Extremely few can use one safely.

They're an elegant weapon for a more civilized age - namely one without multithreading, aliasing-based optimization, and a host of other nice things.

Re:Zig's new LinkedList API (it's time to learn fieldParentPtr) by tauoverpi on Monday April 14, 2025 @05:21PM (#43686457)
Multithreading is exactly where linked lists are useful as in the implementation of MPSC, MPMC, SPMC, and so on it allows one to safely construct objects out of vire of other threads then use a CAS to append the new item to the list making it visible for other threads to consume even without needing to allocate additional memory.

They're also pretty useful for free-list structures which overwrite entries to be removed (they're scheduled for deletion thus assumptiong here is that the object is now dead) with linked list nodes that would fit in that space thus never needing to allocate any additional as you can reuse existing space.

Re:Zig's new LinkedList API (it's time to learn fieldParentPtr) by simonask on Tuesday April 15, 2025 @03:24PM (#43697317)
Yeah, wait-free data structures often contain linked lists. That doesn’t cancel out all of the other problems.

Anecdotally, I’ve seen wait-free structures used incorrectly many more times than I’ve seen them used correctly. Some people think they are magically faster because “acquiring a mutex lock is expensive”, but that’s far from always the case.

Re:Zig's new LinkedList API (it's time to learn fieldParentPtr) by mgaunard on Friday April 18, 2025 @04:51PM (#43731756)
a CAS-loop, as suggested in the message you're replying to, is certainly not wait-free, only lock-free.
Re:Zig's new LinkedList API (it's time to learn fieldParentPtr) by simonask on Thursday April 24, 2025 @10:32AM (#43783295)
Thanks, my mistake. :-)
Re:Zig's new LinkedList API (it's time to learn fieldParentPtr) by codr7 on Wednesday April 16, 2025 @08:30AM (#43704549)
I don't see a problem with their safety, even in C.

More the opposite, their simplicity makes them safer to deal with than the alternatives. And sometimes their unique features (mostly the intrusive variant) are exactly what you need.

Multi-threaded accesses to a vector would be just as bad?

Re:Zig's new LinkedList API (it's time to learn fieldParentPtr) by im3w1l on Monday April 14, 2025 @10:16AM (#43681588)
Implementing anything is more error prone than using something battle-tested.