Boost logo

Boost :

Subject: Re: [boost] [flat_set] When to sort?
From: Oswin Krause (Oswin.Krause_at_[hidden])
Date: 2017-03-27 15:32:09

On 2017-03-27 07:40, Vladimir Batov via Boost wrote:
> On 2017-03-27 10:54, Andrey Semashev wrote:
>>>> How does sort_() handle thread safety? Are you proposing to add a
>>>> mutex to the container?
>>> Yes, I am/was... Is it a problem? I can't see it being a bottle neck
>>> as it
>>> all will be optimized inside sort_() (no unnecessary locks, etc.).
>> I'm sorry, but that is a no-go. Too often containers are used with
>> external locking, and internal locking would just waste performance,
>> especially in such a hot spot as begin(). BTW, I don't believe any
>> compiler is able to optimize away unnecessary locking (thank god!)
> 1. There does not have to be "internal locking would just waste
> performance":
> void sort_()
> {
> if (sorted) return;
> lock
> if (sorted) return;
> actual sorting
> }

Double Checked Locking is notorious for failing randomly. sorted must at
least be atomic.

One of many articles about it:

Boost list run by bdawes at, gregod at, cpdaniel at, john at