rendered paste body#include <iostream>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
void threadSpawn();
boost::try_mutex myMutex;
int main() {
boost::thread foo(threadSpawn);
threadSpawn();
}
void threadSpawn() {
std::cout << "entering threadSpawn" << std::endl;
boost::try_mutex::scoped_try_lock lock(myMutex);
if(lock.locked()) {
std::cout << "locked" << std::endl;
while(true);
} else {
std::cout << "failed to lock" << std::endl;
}
std::cout << "leaving threadSpawn" << std::endl;
}
OUTPUT (as expected):
entering threadSpawn
locked
entering threadSpawn
failed to lock
leaving threadSpawn