Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,586 questions

10,629 answers

573 users

How to get thread id in C++

1 Answer

0 votes
#include <iostream>
#include <thread>

using std::cout;
using std::endl;
using std::thread;

void thread_function()
{
	cout << "thread_function id: " << std::this_thread::get_id() << endl;
}
int main()
{
	thread obj1(thread_function);
	thread obj2(thread_function);

	cout << "main() thread obj1 id: " << obj1.get_id() << endl;
	cout << "main() thread obj2 id: " << obj2.get_id() << endl;

	obj1.join();
	obj2.join();

	return 0;
}

/*
run:

thread_function id: 8948
main() thread obj1 id: 8948
main() thread obj2 id: 5320
thread_function id: 5320

*/

 




answered Feb 6 by avibootz
...