Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » Thread::GetId() returning 0
Thread::GetId() returning 0 [message #50148] Wed, 08 August 2018 13:11 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Hi,

in a MT app I try to use the Thread::GetId() function to check if I'm inside a particular thread,
but I always get 0 as result.
Am I missing something ? The thread is started correctly and also running.

Ciao

Massimo
Re: Thread::GetId() returning 0 [message #50151 is a reply to message #50148] Wed, 08 August 2018 14:29 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Partial reply to myself... I used Start instead of Run, and the thread was detached from variable.
But now, I'm using Thread::GetCurrentId() which should return the Id of calling thread, but returns instead a very big number which has probably nothing to do with it.

How can I check if I'm inside a required thread ? (same as IsMainThread, but something like myThread.Inside())

Ciao

Max
Re: Thread::GetId() returning 0 [message #50170 is a reply to message #50151] Fri, 10 August 2018 20:52 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mdelfede wrote on Wed, 08 August 2018 14:29
Partial reply to myself... I used Start instead of Run, and the thread was detached from variable.
But now, I'm using Thread::GetCurrentId() which should return the Id of calling thread, but returns instead a very big number which has probably nothing to do with it.


OS? Anyway the implementation is really straightforward, so I do not think there should be a bug there...

Quote:

How can I check if I'm inside a required thread ? (same as IsMainThread, but something like myThread.Inside())


What about storing the thread id into thread_local variable at the start of the thread and then test if your GetCurrentId is the same?


Mirek
Re: Thread::GetId() returning 0 [message #50172 is a reply to message #50170] Sat, 11 August 2018 01:17 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Thank you, already solved... OS is Linux, but I guess it was my mistake, using = on IDs instead of pthread_equal.

Ciao

Massimo
Re: Thread::GetId() returning 0 [message #50187 is a reply to message #50172] Mon, 20 August 2018 08:51 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mdelfede wrote on Sat, 11 August 2018 01:17
Thank you, already solved... OS is Linux, but I guess it was my mistake, using = on IDs instead of pthread_equal.

Ciao

Massimo


Well, AFAIK pthread_equal should actually only make portable the code for unlikely case when pthread_t is structure. Are you sure it is the issue?

I am asking because this is really weird.... I expect == to work.

Mirek
Previous Topic: Feature request - GetPeerAddr in WebSocket
Next Topic: [SOLVED] Discord bot 404 error using WebSocket, any ideas?
Goto Forum:
  


Current Time: Thu Mar 28 18:08:29 CET 2024

Total time taken to generate the page: 0.00800 seconds