tdauth / cpp-futures-promises

Advanced futures and promises in C++.
GNU General Public License v3.0
16 stars 0 forks source link

Fix data race bug in firstN and firstNSucc #12

Closed tdauth closed 6 years ago

tdauth commented 6 years ago

There is a data race bug in the firstN and firstNSucc implementations. Make sure that the vector element is added BEFORE the promise is completed. Therefore, do not check if c == n but if the vector's size == n!

According to http://www.cplusplus.com/reference/vector/vector/size/ accessing the vector's size is thread-safe and does not lead to data races. However, to be absolutely sure that the size has the correct value, we can still use the atomic size counter which is increased, after the element is added.

tdauth commented 6 years ago

Is fixed now.