pthread_join(3): If the target thread is detached, return EINVAL.
authorSascha Wildner <saw@online.de>
Sat, 21 Apr 2012 10:17:07 +0000 (12:17 +0200)
committerSascha Wildner <saw@online.de>
Sat, 21 Apr 2012 10:43:31 +0000 (12:43 +0200)
We were returning ESRCH previously, which is wrong, as it indicates
that the thread could not be found. Fix this in both libthread_xu
and libc_r.

See http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_join.html

----->8-----
[ESRCH]
    No thread could be found corresponding to that specified by the
    given thread ID.

...

[EINVAL]
    The value specified by thread does not refer to a joinable thread.
-----8<-----

lib/libc_r/uthread/uthread_join.c
lib/libthread_xu/thread/thr_join.c

index f3dfcf3..4643233 100644 (file)
@@ -30,7 +30,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/lib/libc_r/uthread/uthread_join.c,v 1.12.2.8 2002/10/22 14:44:03 fjoe Exp $
- * $DragonFly: src/lib/libc_r/uthread/uthread_join.c,v 1.3 2005/05/30 20:50:53 joerg Exp $
  */
 #include <errno.h>
 #include <pthread.h>
@@ -100,14 +99,20 @@ _pthread_join(pthread_t pthread, void **thread_return)
        }
 
        /* Check if the thread was not found or has been detached: */
-       if (thread == NULL ||
-           ((pthread->attr.flags & PTHREAD_DETACHED) != 0)) {
+       if (thread == NULL) {
                /* Undefer and handle pending signals, yielding if necessary: */
                _thread_kern_sig_undefer();
 
-               /* Return an error: */
+               /* Thread not found. */
                ret = ESRCH;
 
+       } else if ((pthread->attr.flags & PTHREAD_DETACHED) != 0) {
+               /* Undefer and handle pending signals, yielding if necessary: */
+               _thread_kern_sig_undefer();
+
+               /* Thread is in detached state. */
+               ret = EINVAL;
+
        } else if (pthread->joiner != NULL) {
                /* Undefer and handle pending signals, yielding if necessary: */
                _thread_kern_sig_undefer();
index 5c97a37..21c5868 100644 (file)
@@ -28,8 +28,6 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- *
- * $DragonFly: src/lib/libthread_xu/thread/thr_join.c,v 1.7 2006/04/06 13:03:09 davidxu Exp $
  */
 
 #include "namespace.h"
@@ -94,7 +92,7 @@ join_common(pthread_t pthread, void **thread_return,
        if ((ret = _thr_find_thread(curthread, pthread, 1)) != 0) {
                ret = ESRCH;
        } else if ((pthread->tlflags & TLFLAGS_DETACHED) != 0) {
-               ret = ESRCH;
+               ret = EINVAL;
        } else if (pthread->joiner != NULL) {
                /* Multiple joiners are not supported. */
                ret = ENOTSUP;