/* * Copyright (C) 2004 Aleksandar Colovic * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * */ #include #include #include #include using namespace std; void printThreadInfo(const char* pstrThread) { cout << pstrThread << ": PID=" << getpid() << ", pthread_t=" \ << pthread_self() << ", TID=" << syscall(__NR_gettid) << endl; } void* doWork(void* pArg) { printThreadInfo("Worker thread"); int nSeconds = *(int*)pArg; sleep(nSeconds); } int main(int argc, char* const argv[]) { printThreadInfo("Main thread"); int nSeconds = (argc > 1) ? atoi(argv[1]) : 0; pthread_t hThread; pthread_create(&hThread, 0, &doWork, (void*)&nSeconds); pthread_join(hThread, 0); return 0; };