#include #include #include #include using namespace std; bool gDone = false; int f(int x) { int r = x * 4; return r - 3; } void* mainLoop(void* arg) { while (!gDone) { sleep(5); cout << "MARK: five seconds" << endl; } return NULL; } int main(int argc, char* argv[]) { pthread_t myThread; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); pthread_create(&myThread, &attr, mainLoop, NULL); pthread_attr_destroy(&attr); std::string a = "this is my string"; cout << "string [" << a.size() << "]: " << a << endl; for (int i = 1; i < 10; ++i) cout << "f(" << i << "): " << f(i) << endl; cin >> a; gDone = true; pthread_join(myThread, NULL); return 0; }