Muss der Vektor in diesem Fall durch ein Mutex geschützt werden?



  • vector<bool> kann zu Data Races führen, aber der ist bekanntlich ein Sonderfall.

    23.2.2 Container data races
    ...
    2 Notwithstanding (17.6.5.9), implementations are required to avoid data races when the contents of the contained
    object in different elements in the same sequence, excepting vector<bool>, are modified concurrently.

    3 [ Note: For a vector<int> x with a size greater than one, x[1] = 5 and *x.begin() = 10 can be executed
    concurrently without a data race, but x[0] = 5 and *x.begin() = 10 executed concurrently may result in
    a data race. As an exception to the general rule, for a vector<bool> y, y[0] = true may race with y[1]= true. —end note ]


Anmelden zum Antworten