Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 2 compiler warnings from 1.8.0 #1997

Merged
merged 2 commits into from
Oct 25, 2024
Merged

fix 2 compiler warnings from 1.8.0 #1997

merged 2 commits into from
Oct 25, 2024

Conversation

svigerske
Copy link
Collaborator

Fixed order of initializers in HighsOptionsStruct constructor.

Avoid std::move on temporary std::thread, which gave a clang warning.
The idea of emplace_back is that one can construct the object that is placed into the workerThreads container directly in that container, so one can directly pass the arguments for the constructor of the object to be constructed. (@fwesselm ok?)

- avoid std::move on temporary (fixes clang warning)
- avoid creating temporary std::thread
@jajhall jajhall changed the base branch from master to latest October 24, 2024 09:14
Copy link
Member

@jajhall jajhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing the order of initializers in the HighsOptionsStruct constructor is obviously fine.

These modifications were also spotted by @HaoZeke, but I'm wary of making the other in case it compromises the behaviour of the task scheduler, since @lgottwald and @galabovaa have only just fixed a serious issue in it.

I need to see a clear explanation as to why the task scheduler is unchanged before this PR will be approved.

Also, we don't accept PRs to master.

@svigerske
Copy link
Collaborator Author

svigerske commented Oct 24, 2024

If it were

workerThreads.emplace_back(
          std::thread(&HighsTaskExecutor::run_worker, i, this));

then it would create a std::thread object A, where the constructor is called with arguments &HighsTaskExecutor::run_worker, i, this. Then it would extend the space in the workerThreads container to hold another std::thread object. To initialize this object, it would call the std::thread copy constructor, passing it object A. Then A would be destroyed.

With the std::move, it may put A into the container directly and not destroy A, at least that seems to be the intention of the code.

With the new code, it will extend the space in the workerThreads container to hold another std::thread object. To initialize this object, it will call its constructor with arguments &HighsTaskExecutor::run_worker, i, this. The result should be the same, but the code is more straight forward and a compiler warning on the use of std::move is avoided.

Maybe @lgottwald can just review this part.

Copy link
Contributor

@galabovaa galabovaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you say makes sense and if @lgottwald is happy I'm happy as well!

@lgottwald
Copy link
Contributor

The change should not break anything, but is the temporary object not already an r-value reference? What is the compiler warning?

1 similar comment
@lgottwald
Copy link
Contributor

lgottwald commented Oct 24, 2024

The change should not break anything, but is the temporary object not already an r-value reference? What is the compiler warning?

@svigerske
Copy link
Collaborator Author

svigerske commented Oct 24, 2024

In file included from ipx_control.cpp:1:
In file included from src/parallel/HighsParallel.h:16:
In file included from src/parallel/HighsMutex.h:18:
src/parallel/HighsTaskExecutor.h:132:11: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
          std::move(std::thread(&HighsTaskExecutor::run_worker, i, this)));
          ^
src/parallel/HighsTaskExecutor.h:132:11: note: remove std::move call here
          std::move(std::thread(&HighsTaskExecutor::run_worker, i, this)));
          ^~~~~~~~~~                                                    ~
1 warning generated.

Apple clang version 15.0.0 (clang-1500.3.9.4)

@lgottwald
Copy link
Contributor

lgottwald commented Oct 24, 2024 via email

@jajhall
Copy link
Member

jajhall commented Oct 25, 2024

Happy to merge this now

@jajhall jajhall merged commit 69a1848 into latest Oct 25, 2024
250 checks passed
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.

4 participants