ccia_code_samples icon indicating copy to clipboard operation
ccia_code_samples copied to clipboard

Listing 9.2 - Deprecations

Open ITHelpDec opened this issue 1 year ago • 0 comments

Slight tweaks to address deprecations, unnecessary calls to operator new and use of noexcept with move(-assignment) operations.

There also appears to be a data race when using one of the multithreaded queue implementations from Chapter 6, although this could be as a result of my changes, so I'm open to feedback while I go back to verify with the original implementation.

Possible results - (click to expand / collapse)
void go_forth_and_multiply(std::vector<int> &ivec) {
    thread_pool tp;
    for (int &i : ivec) { tp.submit([&] () { i *= i; }); }
}
ivec: 1 2 3 4 5 6 7 8 9 10 
ivec: 1 4 9 16 25 36 49 64 81 100 

ivec: 1 2 3 4 5 6 7 8 9 10 
ivec: 1 4 9 16 25 36 49 8 9 10 

ivec: 1 2 3 4 5 6 7 8 9 10 
ivec: 1 4 9 16 25 6 7 8 9 10 

ivec: 1 2 3 4 5 6 7 8 9 10 
ivec: 1 2 3 4 5 6 7 8 9 10 

for (int i = 0; i != ivec.size(); ++i) {
    tp.submit([&, i] () { ivec[i] *= ivec[i]; });
}

...produces similar results.

ITHelpDec avatar Jul 08 '23 15:07 ITHelpDec