Skip to content

Conversation

@ITHelpDec
Copy link

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 added 3 commits July 8, 2023 15:14
- `std::result_of` was deprecated as of C++17, and removed in C++20
- opt for `std::invoke_result_t` in its place for all instances
- also improves brevity
- move and move-assignment operations should not throw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant