কম্পিউটার টিউটোরিয়াল

C++-এ থ্রেড get_id() ফাংশন


এই টিউটোরিয়ালে, আমরা C++-এ থ্রেড `get_id()` ফাংশন সম্পর্কে একটি প্রোগ্রাম আলোচনা করব।

থ্রেড `get_id()` ফাংশন বর্তমান প্রসেসের স্টেট যাচাই করে এবং এক্সিকিউশনে থাকা বর্তমান থ্রেডের আইডি রিটার্ন করে। এই ফাংশন কোনো প্যারামিটার নেয় না।

উদাহরণ

#include <chrono> #include <iostream> #include <thread> using namespace std; //creating thread void sleepThread(){    this_thread::sleep_for(chrono::seconds(1)); } int main(){    thread thread1(sleepThread);    thread thread2(sleepThread);    thread::id t1_id = thread1.get_id();    thread::id t2_id = thread2.get_id();    cout << "ID associated with thread1= " << t1_id << endl;    cout << "ID associated with thread2= " << t2_id << endl;    thread1.join();    thread2.join();    return 0; }

আউটপুট

ID associated with thread1= 135456142132844 ID associated with thread2= 135121414221716

  1. C++-এ strtol() ফাংশন

  2. সি++ STL-এ transform() ফাংশন

  3. C++-এ log() ফাংশন

  4. C++-এ swap() ফাংশন