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
Remove Thread::kill() and related unittest #10317
Conversation
if we use only kill on our test, it's just a useless method. Drop it, less maintenance to do on dead called code :) |
It is still called by Thread destructor. I guess the code could be moved there then. |
i agree with you @pyrollo |
I will look to merge the kill() method inside the destructor
|
The Thread kill() method isn't used outside testThreadKill unit test and Thread destructor. It could be make private. The testThreadKill test should be removed: it tests the kill() feature in a way minetest doesn't use it (kill and restart a thread), specially because some pthreads implementations on BSD will not allow to lock again the m_start_finished_mutex which is hold when the thread is killed. Closes: #6065
Looks good to me but I have no BSD setup to test on. |
It shouldn't require a BSD to test.
The testThreadKill tested that a Thread could be killed and restarted safely (something not used in minetest). But it was relying on undefined behaviour for that: the fact that a random thread could unlock a mutex hold by a cancelled thread (something forbidden on BSD, but allowed with glibc on Linux).
Now that the `kill()` method is merged in the destructor, it is explicit that a Thread is killed only in the destructor: the thread couldn't be reused.
|
as you are in destructor, you can drop all asignment there because after destructor we won't read them :D
I was more concerned by concurrent access than about what can happens after destructor.
I don't know enough C++ to be sure that if the destructor is called it means really nothing has reference on it and could race with the code inside the destructor. So I was conservative.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine.
src/threading/thread.cpp
Outdated
m_retval = nullptr; | ||
m_joinable = false; | ||
m_request_stop = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as Nerzhul told above, these assignments are useless now.
Ok for me once superfluous assignments removed. |
I removed the assigments done after killing the thread, but keep the one before
(m_running = false), as in !_WIN32 case, the code will call `wait()` function,
and there is an assert on `m_running`.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works on Linux.
Performing a test on (virtual) Windows before merging. |
The Thread kill() method isn't used outside testThreadKill unit test
and Thread destructor. It could be make private.
The testThreadKill test should be removed: it tests the kill() feature
in a way minetest doesn't use it (kill and restart a thread), specially
because some pthreads implementations on BSD will not allow to lock
again the m_start_finished_mutex which is hold when the thread is
killed.
Closes: #6065
This PR is Ready for Review.
Eventually, the
Thread::kill()
method could be merged insideThread::~Thread()