Why #if ISTHREADSAFE boost::mutex::scoped_lock lock(CacheInfo_mutex); # endif functions well , but not if(isThreadSafe) { boost::mutex::scoped_lock lock(CacheInfo_mutex); }