Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make thread attach/detach behavior less annoying to work with. #214

Merged
merged 1 commit into from

2 participants

@alexrp
Collaborator

This just makes it so attaching an already-attached thread or detaching
an already-detached thread doesn't result in undefined behavior and/or
Bad Things (TM). Making the user do these checks is fairly pointless
because they almost always have to be done. We may as well do them
internally.

alexrp Make thread attach/detach behavior less annoying to work with.
This just makes it so attaching an already-attached thread or detaching
an already-detached thread doesn't result in undefined behavior and/or
Bad Things (TM).
ef4338a
@MartinNowak MartinNowak merged commit 8b581f7 into from
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 17, 2012
  1. Make thread attach/detach behavior less annoying to work with.

    alexrp authored
    This just makes it so attaching an already-attached thread or detaching
    an already-detached thread doesn't result in undefined behavior and/or
    Bad Things (TM).
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 4 deletions.
  1. +9 −2 src/core/thread.d
  2. +2 −2 src/core/thread.di
View
11 src/core/thread.d
@@ -1897,12 +1897,15 @@ extern (C) bool thread_isMainThread()
/**
* Registers the calling thread for use with the D Runtime. If this routine
- * is called for a thread which is already registered, the result is undefined.
+ * is called for a thread which is already registered, no action is performed.
*/
extern (C) Thread thread_attachThis()
{
gc_disable(); scope(exit) gc_enable();
+ if (auto t = Thread.getThis())
+ return t;
+
Thread thisThread = new Thread();
Thread.Context* thisContext = &thisThread.m_main;
assert( thisContext == thisThread.m_curr );
@@ -1987,6 +1990,9 @@ version( Windows )
{
gc_disable(); scope(exit) gc_enable();
+ if (auto t = thread_findByAddr(addr))
+ return t;
+
Thread thisThread = new Thread();
Thread.Context* thisContext = &thisThread.m_main;
assert( thisContext == thisThread.m_curr );
@@ -2084,7 +2090,8 @@ version( Windows )
*/
extern (C) void thread_detachThis()
{
- Thread.remove( Thread.getThis() );
+ if (auto t = Thread.getThis())
+ Thread.remove(t);
}
View
4 src/core/thread.di
@@ -465,7 +465,7 @@ extern (C) bool thread_isMainThread();
/**
* Registers the calling thread for use with the D Runtime. If this routine
- * is called for a thread which is already registered, the result is undefined.
+ * is called for a thread which is already registered, no action is performed.
*/
extern (C) Thread thread_attachThis();
@@ -492,7 +492,7 @@ version( Windows )
/**
* Deregisters the calling thread from use with the runtime. If this routine
- * is called for a thread which is not registered, the result is undefined.
+ * is called for a thread which is not registered, no action is performed.
*/
extern (C) void thread_detachThis();
Something went wrong with that request. Please try again.