4 ms·
Ask HN: What's your favorite lock free data structure?
- chrisbennet 8y agoRing buffer. When it comes to multithreading, I avoid using things like semaphores, mutexes and locks.
- sgillen 8y agoWhy do you avoid mutexes and locks? Are they just hard to make bug free when you start scaling them up?
- chrisbennet 8y agoFor me, multithreading is um complicated. I told someone once that I view people who say that “multithreading is easy” the same way I view a young man who says “I understand women.” All kidding aside, most programs require some sort of multithreading but the ones I write haven’t needed explicit mutex, semaphores or locks. (And I’ve been doing this 30+ years.)
- quickthrower2 8y agoSTM in Haskell is quite nice. I only had a quick play with it, and it was quite a while ago, but the idea IIRC is that you can put messages on Queues called Channels and then consume them. Here is something I knocked up: https://github.com/mcapodici/haskelllearn/tree/master/stockexchangeprototype https://github.com/mcapodici/haskelllearn/tree/master/stocke...
- kasey_junk 8y agoFairly certain STM is implemented with locks, at least weiteSets are.
- quickthrower2 8y agoAh perhaps. It certainly nicer than an explicit locks in "business" code
- kasey_junk 8y agoSure. But in this context I assume the question is about a specific class of algorithm: https://en.m.wikipedia.org/wiki/Non-blocking_algorithm https://en.m.wikipedia.org/wiki/Non-blocking_algorithm Lots of abstractions ‘hide’ the locks from you. Very few are lock free.