在LINUX系统中,POSIX threads库提供了pthread_t来标识一个线程,通过pthread_self()可以得到,如下: #include <iostream> #include <pthread.h> using namespace std; void* thread_func(void*) { //pthread_t other_thread_id = pthread_self(); //cout << "other_thread_id=" << other_thread_id << endl; return NULL; } int main(int argc, char *argv[]) { pthread_t t1, t2; pthread_create(&t1, NULL, thread_func, NULL); cout << t1 << endl; pthread_join(t1, NULL); //pthread_create(&t2, NULL, thread_func, NULL); //cout << t2 << endl; //pthread_join(t2, NULL); return 0; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 得到结果: