I'm trying to get into boost threads but I'm at a loss by examples and challenges by which to learn, so I was trying to remember an example in my java course where a user is prompted for a password, and if they don't enter it and allow the thread to complete normally the thread ends. I was trying to recreate this but it doesn't seem to be working. I know what mutexes do but I don't know if I'm using the right strategy. How do I get a thread to "time out"?
Edit: I try to remove the join on the thread but it doesn't even execute before ending.Code:#include <string> #include <iostream> #include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> #include <boost/bind.hpp> using std::cout; using std::cin; using std::endl; using std::string; boost::timed_mutex timedMutex; const string pass("somejunk"); void login(string name) { boost::timed_mutex::scoped_lock (timedMutex, 200); string attempt; while(attempt != pass) { cout << "Enter the password " << name <<" : "; cin >> attempt; } cout << "Access Granted" << endl; } int main() { boost::thread athread(boost::bind(login, "Daniel")); athread.join(); return 0; }