When I execute the following code in Visual Studio on local windows computer,it runs well.But when I connect it to My Linux in virtual machine,there's something wrong with it.
error info on local windows:The current stack frame was not found in a loaded module.
Source cannot be shown for this location.
error in Linux Console Window:terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Here's the code:
#include<thread>
#include<string>
using namespace std;
void hello(string user_name) {
cout << "hello," << user_name << "\n";
cout << std::this_thread::get_id << endl;
}
class scopedThread {
private:
thread t;
public:
explicit scopedThread(thread loc) :t(move(loc)) {
cout << "construct!" << endl;
if (!t.joinable()) {
throw logic_error("the thread is unjoinable!");
}
}
~scopedThread() {
cout << "deconstruct!" << endl;
cout << std::this_thread::get_id << "scopedthread1" << endl;
t.join();
cout << std::this_thread::get_id << "scopedthread2" << endl;
}
scopedThread(scopedThread const&) = delete;
scopedThread& operator=(scopedThread const&) = delete;
};
int main()
{
string name;
cin >> name;
scopedThread t(thread(hello, name));
cout << "tian huang bi xia!" << endl;
return 0;
}
What should I do?
What's the difference between the two compiler?And can I adjust the remote Linux Console in Visual Studio?
Thanks in advance.
p.s.:My compiler on remote Linux is gcc/g++.