C++ APISession methods
get_io_thread_id
Returns the internal I/O thread ID used by the current session object.
get_io_thread_id returns the internal worker-thread ID used by the current
blaze::session.
Function variants
std::thread::id get_io_thread_id() const;Inspection helper only
get_io_thread_id does not send any API packet and does not inspect
initialization or authorization state. It is a local diagnostic/helper
method.
Result
std::thread::id| Type | Meaning |
|---|---|
std::thread::id | The internal I/O thread identity used by this blaze::session object. |
Behavior notes
- This method is mainly useful for diagnostics, assertions, or guarding against misuse of sync API from async callbacks.
- Compare it with
std::this_thread::get_id()if you need to know whether current code is running on the library I/O thread. - This method does not indicate whether the session is connected, initialized, or authorized.
- Different
blaze::sessioninstances may have different I/O thread IDs. - Copies created from the same
blaze::sessionshare the same underlying session state and therefore the same I/O thread.
Example
Compilation note
This example compiles in the same form from C++14 to C++26.
#include "blazeauth/api/api.hpp"
#include <iostream>
#include <thread>
int main() {
blaze::session session;
const std::thread::id io_thread_id = session.get_io_thread_id();
const std::thread::id current_thread_id = std::this_thread::get_id();
std::cout << "Current thread id: " << current_thread_id << '\n';
std::cout << "Session I/O thread id: " << io_thread_id << '\n';
if (current_thread_id == io_thread_id) {
std::cout << "Current code is running on the library I/O thread\n";
} else {
std::cout << "Current code is not running on the library I/O thread\n";
}
return 0;
}