Answer by HolyBlackCat for What is the right std::atomic memory order for...
relaxed is ok, because regardless of memory order, each separate atomic variable is always consistent across all threads.Memory orders are only necessary when you have more than one variable (atomic or...
View ArticleAnswer by Peter Cordes for What is the right std::atomic memory order for...
relaxed is sufficient.Every counter.fetch_add(1, relaxed) will return a different value, and every value from 0 upwards will be returned once. Atomicity alone guarantees this since all operations are...
View ArticleAnswer by xryl669 for What is the right std::atomic memory order for dynamic...
I think you're confusing with a CAS (compare and swap) operation here.fetch_add is not a CAS, it's defined as a Read Modify Write atomic operation. It's not equivalent to atomic_var.compare_exchange(i,...
View ArticleWhat is the right std::atomic memory order for dynamic scheduling?
I am wondering what the correct memory order is for the classic "atomic counter dynamic scheduling" idiom. That is:use fetch-add to get the index i of the next element to processif i is past the end of...
View Article
More Pages to Explore .....