From: "ross.johnson" <ross.johnson@homemail.com.au>
To: Markus Forrer <markus.forrer@gmx.ch>, pthreads-win32@sourceware.org
Subject: RE: isCurrentThread()
Date: Sun, 04 Apr 2021 08:15:00 +1000 [thread overview]
Message-ID: <0b07f0$9kg5f8@icp-osb-irony-out7.iinet.net.au> (raw)
In-Reply-To: <trinity-659b4c47-b554-482f-905c-665e8be6bbb1-1617437785049@3c-app-gmx-bs35>
In pthreads-win32 (now pthreads4w on SourceForge), the pthread handle pthread_t is not the W32ThreadHandle. If you want the corresponding W32 thread handle you can use the function:HANDLE
pthread_getw32threadhandle_np(pthread_t thread);
Returns the win32 thread handle that the POSIX
thread "thread" is running as.
Applications can use the win32 handle to set
win32 specific attributes of the thread.If you want the W32 thread ID use:DWORD
pthread_getw32threadid_np (pthread_t thread)
Returns the Windows native thread ID that the POSIX
thread "thread" is running as.
Only valid when the library is built where
! (defined(__MINGW64__) || defined(__MINGW32__)) || defined (__MSVCRT__) || defined (__DMC__)
and otherwise returns 0.
As the _np suffix indicates, these are not portable functions.Another way you may be able to track and manage your threads is to use:__int64
pthread_getunique_np (pthread_t thr)
Returns the unique number associated with thread thr.
The unique numbers are a simple way of positively identifying a thread when
pthread_t cannot be relied upon to identify the true thread instance. I.e. a
pthread_t value may be assigned to different threads throughout the life of a
process.
Because pthreads4w (pthreads-win32) threads can be uniquely identified by their
pthread_t values this routine is provided only for source code compatibility.
NOTE: if the library is re-initialised, i.e. by calling pthread_win32_process_detach_np()
followed by pthread_win32_process_attach_np(), then the unique number is reset along with
several other library global values. Library reinitialisation should not be required,
however, some older applications may still call these routines as they were once required to
do when statically linking the library.Again, this is non portable but several other pthreads implementations provide it.Sent from my phone
-------- Original message --------From: Markus Forrer via Pthreads-win32 <pthreads-win32@sourceware.org> Date: 3/4/21 7:16 pm (GMT+10:00) To: pthreads-win32@sourceware.org Subject: isCurrentThread() I have implemented a method in my thread class Win32Thread to find out if it is the current thread:bool Win32Thread::isCurrentThread() const{ pthread_t currentThread = pthread_self(); return pthread_equal(currentThread, mThread) != 0;}Unfortunately, this implementation does not work. The function pthread_self() gets the current win32 threadId with GetCurrentThreadId(). But how do I have to check in my method isCurrentThread() if the current instance of Win32Thread is the current thread? I have not found an alternative to pthread_equal() in the PThread Api.Thanks for any hintsMarkus
next prev parent reply other threads:[~2021-04-03 22:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-03 8:16 isCurrentThread() Markus Forrer
2021-04-03 22:15 ` ross.johnson [this message]
2021-04-08 4:43 ` isCurrentThread() Markus Forrer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='0b07f0$9kg5f8@icp-osb-irony-out7.iinet.net.au' \
--to=ross.johnson@homemail.com.au \
--cc=markus.forrer@gmx.ch \
--cc=pthreads-win32@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).