DEV Community

Dheeraj Jha
Dheeraj Jha

Posted on

Thread: Mutex sucks

We can syncronize threads with mutex, then what is the need of Condition Variable.
Whenever we start learning multithreading and mutex, we see some examples with mutex and CV. I found most of them does not explain the need of Condition Variable, it was very confusing for me.
Now I know why it is required, I am trying to simulate the problem. Solution is of course Condition Variable.
Please go through this article and let me know your suggestions. Critics are most welcome.

https://www.jhadheeraj.com/post/condition-variable-what-is-the-problem-with-mutex-alone

Top comments (3)

Collapse
 
bittnkr profile image
bittnkr • Edited

I think you may like something I found:

github.com/bittnkr/uniq

Its an implementation on a lock free queue, with it, you can code multi threaded apps without a single Mutex.

It's very fast and rock solid.

Take a look and tell me what you think.

Collapse
 
jhadheeraj1986 profile image
Dheeraj Jha

Lock free queue sounds interesting. Let me check it.

Collapse
 
bittnkr profile image
bittnkr • Edited

Nice... If you need help, just call me. Currently I'm working alone on it, and will be a pleasure to have have someone to share ideas.

Note that, despite the main test being a producer/consumer pushing integers, it is implemented with generics, you can push anything you want on into the queue, with any number of concurrent threads.

Currently I'm trying to implement some kind of future/promises on it, to make easier to push function calls on it. If you like to handle low level stuff as messing with stack registers I can send you the first drafts.

And recently I've updated the C# version too, it is a lot more readable.