Re: FXThread::current() changed behavior between FOX-1.6.x and FOX-1.7 in WIN32

Jeroen van der Zijp <[email protected]>
Newsgroups gmane.comp.lib.fox-toolkit.user
Organization FOX Toolkit
Message-ID <[email protected]>
On Sat, 08 Apr 2023 22:02:19 +0200
Martin Oberzalek <[email protected]> wrote:

> Hi,
> 
> my app used FXThread::current() to have a kind of identifier for each
> thread. So a central function was able to know wich thread called it,
> without the need for getting an extra handle to the thread class
> itself.
> 
> I implemented a thread specific cache this way. However...
> 
> A recent dev FOX version returns GetCurrentThread() on WIN32.
> The current code is:
> 
> // Return thread id of caller
> FXThreadID FXThread::current(){
> #if defined(WIN32)
> //return (FXThreadID)GetCurrentThreadId();
>   return (FXThreadID)GetCurrentThread();
> #else
>   return (FXThreadID)pthread_self();
> #endif
>   }
> 
> But GetCurrentThread() returns a pseudo handle. It is always
> 0xFFFFFFFFFFFFFFFE or in decimal: it is always -2
> https://learn.microsoft.com/en-
> us/windows/win32/api/processthreadsapi/nf-processthreadsapi-
> getcurrentthread
> 
> The Unix version pthread_self() returns always the same handle, that
> returned when creating a thread.
> 
> https://man7.org/linux/man-pages/man3/pthread_self.3.html
> The  pthread_self()  function returns the ID of the calling thread. 
> This is the same value that is returned in *thread in the
> pthread_create(3) call that created this thread.
> 
> so implified:
> for POSIX systems: pthread_create() == pthread_self()
> for WIN32 systems: CreateThread() == GetCurrentThreadId()
> 
> I suggest swithing back to the GetCurrentThreadId() version,
> otherwise it would be wise to dokument the different behaviour between
> POSIX and WIN32

OK, you're right, there doesn't seem to be much that you'd be able
to do with psuedo-handle.

I reverted it to the thread id.

The actual handle can be self()->id(), except for the main thread.


     -- JVZ


_______________________________________________
Foxgui-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/foxgui-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.