Ask HN: What's your favorite lock free data structure? - mrburton
======
quickthrower2
STM 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/stocke...](https://github.com/mcapodici/haskelllearn/tree/master/stockexchangeprototype)

~~~
kasey_junk
Fairly certain STM is implemented with locks, at least weiteSets are.

~~~
quickthrower2
Ah perhaps. It certainly nicer than an explicit locks in "business" code

~~~
kasey_junk
Sure. 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.

------
chrisbennet
Ring buffer. When it comes to multithreading, I avoid using things like
semaphores, mutexes and locks.

~~~
sgillen
Why do you avoid mutexes and locks? Are they just hard to make bug free when
you start scaling them up?

~~~
chrisbennet
For 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.)

