I'd like to have a class member of type std::thread::id
where I can also nullify it and then check whether it has been set.
What is the best way to "nullify" this type and then check whether it has been set?
std::thread::id The class thread::id is a lightweight, trivially copyable class that serves as a unique identifier of std::thread and std::jthread (since C++20) objects. Instances of this class may also hold the special distinct value that does not represent any thread.
In the run() method, we use the currentThread(). getName() method to get the name of the current thread that has invoked the run() method. We use the currentThread(). getId() method to get the id of the current thread that has invoked the run() method.
The pthread_getname_np() function retrieves the name of the thread. The buffer specified by name must be at least 16 characters in length. The returned thread name will be null terminated in the output buffer. By default, each thread is unnamed.
pthread_t is the data type used to uniquely identify a thread.
According to cppreference on std::thread::id (default constructor):
Default-constructs a new thread identifier. The identifier does not represent a thread.
So, you can store and compare against a default constructed std::thread::id
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With