एक साधारण प्रोग्राम है: मैं इस गेटिड फ़ंक्शन का उपयोग करके दोनों धागे की थ्रेड आईडी प्राप्त करना चाहता हूं। मैं सीधे sysCall नहीं करना चाहता। मैं इस समारोह का उपयोग करना चाहता हूँ।सी ++ गेटिड() इस दायरे में घोषित नहीं किया गया था
#include <iostream>
#include <boost/thread/thread.hpp>
#include <boost/date_time/date.hpp>
#include <unistd.h>
#include <sys/types.h>
using namespace boost;
using namespace std;
boost::thread thread_obj;
boost::thread thread_obj1;
void func(void)
{
char x;
cout << "enter y to interrupt" << endl;
cin >> x;
pid_t tid = gettid();
cout << "tid:" << tid << endl;
if (x == 'y') {
cout << "x = 'y'" << endl;
cout << "thread interrupt" << endl;
}
}
void real_main() {
cout << "real main thread" << endl;
pid_t tid = gettid();
cout << "tid:" << tid << endl;
boost::system_time const timeout = boost::get_system_time() + boost::posix_time::seconds(3);
try {
boost::this_thread::sleep(timeout);
}
catch (boost::thread_interrupted &) {
cout << "thread interrupted" << endl;
}
}
int main()
{
thread_obj1 = boost::thread(&func);
thread_obj = boost::thread(&real_main);
thread_obj.join();
}
यह संकलन पर त्रुटि देता है; gettid के उपयोग() आदमी पृष्ठ के अनुसार किया गया है:
$g++ -std=c++11 -o Intrpt Interrupt.cpp -lboost_system -lboost_thread
Interrupt.cpp: In function ‘void func()’:
Interrupt.cpp:17:25: error: ‘gettid’ was not declared in this scope
pid_t tid = gettid();
"कोई ग्लिबैक रैपर नहीं है" कहने के बारे में "स्पष्ट रूप से कहा गया" कुछ भी नहीं है। –