Live data from Hacker News

A collection of lock-free data structures written in standard C++11

github.com

11–20 of 86 posts

Re: A collection of lock-free data structures written in standard C++11

#11

I've only looked at the queue implementation, but both push and pop contain obvious race conditions; I would highly suggest adding tests that actually use the data structures from multiple threads.

Could you elaborate on the alleged race conditions? Any advice on reliably testing the race conditions? The problem with adding those is the fact that they will give lots of false negatives and if you rely on them you have a problem.

Re: A collection of lock-free data structures written in standard C++11

#12

Every datastructure is lock free. Locks are required when you have multiple writers. The article states the usefull only for certain circumstance: for single consumer single producer scenarios. So yea within these assumptions you can make something work.

You may need a lock if you have operations that are not atomic, even with a single writer, as a reader could find an inconsistency.

Re: A collection of lock-free data structures written in standard C++11

#13

Every datastructure is lock free. Locks are required when you have multiple writers. The article states the usefull only for certain circumstance: for single consumer single producer scenarios. So yea within these assumptions you can make something work.

This seems unnecessarily pedantic. Lock-free conventionally implies concurrent, otherwise it's meaningless.

Re: A collection of lock-free data structures written in standard C++11

#14

Every datastructure is lock free. Locks are required when you have multiple writers. The article states the usefull only for certain circumstance: for single consumer single producer scenarios. So yea within these assumptions you can make something work.

Even in single producer single consumer scenarios you need locks for multithreaded/interrupt use if you're not properly using atomics and proper fences.

Re: A collection of lock-free data structures written in standard C++11

#16
post #11

I've only looked at the queue implementation, but both push and pop contain obvious race conditions; I would highly suggest adding tests that actually use the data structures from multiple threads.

Could you elaborate on the alleged race conditions? Any advice on reliably testing the race conditions? The problem with adding those is the fact that they will give lots of false negatives and if you rely on them you have a problem.

Looking at the Push operation defined in queue_impl.hpp, if multiple threads perform concurrent pushes, they might end up writing their element to the same slot in _data since the current position _w is not incremented atomically

Re: A collection of lock-free data structures written in standard C++11

#17

Every datastructure is lock free. Locks are required when you have multiple writers. The article states the usefull only for certain circumstance: for single consumer single producer scenarios. So yea within these assumptions you can make something work.

[flagged]

Re: A collection of lock-free data structures written in standard C++11

#18
post #11

I've only looked at the queue implementation, but both push and pop contain obvious race conditions; I would highly suggest adding tests that actually use the data structures from multiple threads.

Could you elaborate on the alleged race conditions? Any advice on reliably testing the race conditions? The problem with adding those is the fact that they will give lots of false negatives and if you rely on them you have a problem.

You could use TLA+ to model the data structure operations and check the invariant. Checking the invariant with assert is also useful in my limited experience with concurrency.

https://lamport.azurewebsites.net/tla/tla.html

Re: A collection of lock-free data structures written in standard C++11

#19
post #11

Earlier quoted context omitted.

Could you elaborate on the alleged race conditions? Any advice on reliably testing the race conditions? The problem with adding those is the fact that they will give lots of false negatives and if you rely on them you have a problem.

Looking at the Push operation defined in queue_impl.hpp, if multiple threads perform concurrent pushes, they might end up writing their element to the same slot in _data since the current position _w is not incremented atomically

This is a multi producer scenario, the README clearly states that these data structures are only single producer single consumer multi thread/interrupt safe.

I will also add disclaimers to the javadocs comments on methods just to reduce confusion.

Re: A collection of lock-free data structures written in standard C++11

#20
post #18
post #11

Earlier quoted context omitted.

Could you elaborate on the alleged race conditions? Any advice on reliably testing the race conditions? The problem with adding those is the fact that they will give lots of false negatives and if you rely on them you have a problem.

You could use TLA+ to model the data structure operations and check the invariant. Checking the invariant with assert is also useful in my limited experience with concurrency. https://lamport.azurewebsites.net/tla/tla.html

Thanks a lot, will check this out!
Post reply on HN