Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Fix issue 18063 - thread_attachThis returns dangling pointer #1986

Closed
wants to merge 2 commits into from

Conversation

acehreli
Copy link

Prevent returning dangling pointer as well as call all detach varieties after locking slock. (All other calls to Thread.remove() are done while holding slock.)

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @acehreli! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

Some tips to help speed things up:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

Bear in mind that large or tricky changes may require multiple rounds of review and revision.

Please see CONTRIBUTING.md for more information.

Bugzilla references

Auto-close Bugzilla Description
18063 thread_attachThis returns dangling pointer

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

@dlang-bot dlang-bot added the Bug Fix Include reference to corresponding bugzilla issue label Dec 11, 2017
@@ -2239,8 +2244,14 @@ version( Windows )
*/
extern (C) void thread_detachThis() nothrow @nogc
{
Thread.slock.lock_nothrow();
scope(exit) Thread.slock.unlock_nothrow();
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, these changes should be in the separate commit.

Copy link
Author

Choose a reason for hiding this comment

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

Agreed but I could not pass my test program without fixing these as well. Perhaps I should open two bugs and submit fixes for two.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just add extra commit in this PR? Make the first commit to add locks, and the second commit (which includes Fixes issue ... entry) with t.setThis(null) and doc change?

{
t.stopRequested = true;
while (!t.stopped)
Thread.sleep(1000.msecs);
Copy link
Author

Choose a reason for hiding this comment

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

I hadn't realized that this sleep was so long. Reducing it to 1.mecs causes a segfault. Working on it...

@acehreli
Copy link
Author

Closing for now as I'm not sure whether SIGSEGV during pthread_detach() inside code/thread.d is a druntime or a test code bug.

@acehreli acehreli closed this Dec 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Fix Include reference to corresponding bugzilla issue
Projects
None yet
3 participants