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

Thread: fix a crash on Windows due to data race condition on Thread::m_start_finished_mutex #6515

Merged
merged 1 commit into from
Oct 10, 2017

Conversation

nerzhul
Copy link
Member

@nerzhul nerzhul commented Oct 9, 2017

m_start_finished_mutex is not unlocked by thread when exiting the thread::run function.
On windows TerminateHandle kill the thread but doesn't release mutexes owned by it, it's a dangerous function.
On VS2017 when calling Thread destructor and trying to unlock, it's refused by system because mutex is not owned by this thread.

@nerzhul nerzhul added Bugfix 🐛 PRs that fix a bug Windows labels Oct 9, 2017
// Unlock m_start_finished_mutex to prevent data race condition on Windows.
// On Windows with VS2017 build TerminateThread is called and this mutex is not
// released. We try to unlock it from caller thread and it's refused by system.
thr->m_start_finished_mutex.unlock();
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be inside an #ifdef _WIN32 then?

Copy link
Member Author

Choose a reason for hiding this comment

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

on android it's also undefined behaviour, we use pthread_kill, and it's better to do it properly

@nerzhul
Copy link
Member Author

nerzhul commented Oct 10, 2017

@nerzhul nerzhul merged commit 32ae492 into minetest:master Oct 10, 2017
@nerzhul nerzhul deleted the vs2017_thread_crashfix branch October 10, 2017 10:27
sfan5 pushed a commit that referenced this pull request Nov 19, 2017
@sfan5 sfan5 mentioned this pull request Dec 5, 2017
sfan5 pushed a commit that referenced this pull request Dec 5, 2017
t0ny2 pushed a commit to t0ny2/minetest that referenced this pull request Jan 23, 2018
sfan5 pushed a commit that referenced this pull request Feb 2, 2018
sfan5 pushed a commit that referenced this pull request Feb 3, 2018
sfan5 pushed a commit that referenced this pull request Apr 21, 2018
sfan5 pushed a commit that referenced this pull request May 13, 2018
SmallJoker pushed a commit that referenced this pull request Jun 3, 2018
osjc pushed a commit to osjc/minetest that referenced this pull request Jan 11, 2019
osjc pushed a commit to osjc/minetest that referenced this pull request Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants