Apparently these 2 error codes have been removed in recent versions of
POSIX:
*
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_detach.html
*
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html
I don't know if there's a way to signal what version of POSIX winpthread
is following or if we should only handle the newer error code
On 2022-03-15 16:40, Steve Lhomme wrote:
According to the pthread_detach() documentation [1] it should return EINVAL the
thread is not a joinable thread. ESRCH is when the thread doesn't correspond to
an existing thread.
This is the same thing for pthread_join() [2]. ESRCH is only when the thread
doesn't correspond to an existing thread.
For detached threads, tv->h is set to NULL so we can't use that to check
whether the value is valid or not.
[1] https://man7.org/linux/man-pages/man3/pthread_detach.3.html
[2] https://man7.org/linux/man-pages/man3/pthread_join.3.html
---
mingw-w64-libraries/winpthreads/src/thread.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/mingw-w64-libraries/winpthreads/src/thread.c
b/mingw-w64-libraries/winpthreads/src/thread.c
index e3edbae8a..61268f921 100644
--- a/mingw-w64-libraries/winpthreads/src/thread.c
+++ b/mingw-w64-libraries/winpthreads/src/thread.c
@@ -1686,10 +1686,12 @@ pthread_join (pthread_t t, void **res)
struct _pthread_v *tv = __pth_gpointer_locked (t);
pthread_spinlock_t new_spin_keys = PTHREAD_SPINLOCK_INITIALIZER;
- if (!tv || tv->h == NULL || !GetHandleInformation(tv->h, &dwFlags))
+ if (!tv)
return ESRCH;
- if ((tv->p_state & PTHREAD_CREATE_DETACHED) != 0)
+ if (tv->h == NULL && (tv->p_state & PTHREAD_CREATE_DETACHED) != 0)
return EINVAL;
+ if (tv->h == NULL || !GetHandleInformation(tv->h, &dwFlags))
+ return ESRCH;
if (pthread_equal(pthread_self(), t))
return EDEADLK;
@@ -1773,16 +1775,21 @@ pthread_detach (pthread_t t)
pthread_spinlock_t new_spin_keys = PTHREAD_SPINLOCK_INITIALIZER;
pthread_mutex_lock (&mtx_pthr_locked);
- if (!tv || tv->h == NULL || !GetHandleInformation(tv->h, &dwFlags))
+ if (!tv)
{
pthread_mutex_unlock (&mtx_pthr_locked);
return ESRCH;
}
- if ((tv->p_state & PTHREAD_CREATE_DETACHED) != 0)
+ if (tv->h == NULL && (tv->p_state & PTHREAD_CREATE_DETACHED) != 0)
{
pthread_mutex_unlock (&mtx_pthr_locked);
return EINVAL;
}
+ if (tv->h == NULL || !GetHandleInformation(tv->h, &dwFlags))
+ {
+ pthread_mutex_unlock (&mtx_pthr_locked);
+ return ESRCH;
+ }
/* if (tv->ended) r = ESRCH; */
dw = tv->h;
tv->h = 0;
--
2.29.2
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public