Answer the question
In order to leave comments, you need to log in
How to get a pointer to the thread that called it in a function?
I create a thread (thread):
std::thread *thr = new std::thread(&MyClass::threadFunc, this);
How now in the MyClass::threadFunc() function to get a pointer to the thread that called it?
Answer the question
In order to leave comments, you need to log in
In the standard library, you can get the thread id. You can try to compare it with a pre-stored id.
In Qt, you can get a pointer to a thread like this:
or find out which thread an object is in:QThread * QObject::thread() const
Do you want to have a std::thread* pointer inside MyClass?
-Make this pointer global.
- Pass the pointer through the class method MyClass.
-Make a global function to access this pointer.
-Make a global singleton class to access this pointer.
-Make a class method that spawns this very thread, which is a member of the class.
- etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question