L
layman
class Dictionary
{
public :
Dictionary()
{
pthread_mutex_init(&mutex_,0)
}
virtual ~Dictionary()
{
pthread_mutex_destroy(&mutex_);
}
std::String transalate(std::string word) throw (std::string)
{
pthread_mutex_lock(&mutex_);
if (dict.find(word) == dict.end())
{
throw std::string(word + "not found");
}
std::string transalation = dict[MH:word];
pthread_mutex_unlock(&mutex_);
return transalation;
}
void addToDictionary (std::string word,std::string
transalation) throw (std::string)
{
pthread_mutex_lock(&mutex_);
if (dict.find(word)!=dict.end())
{
throw std::string(word + "already exits");
}
dict[MH:word]=transalation;
pthread_mutex_unlock(&mutex_);
}
private:
typedef std::map<std::string,std ::string>dictType;
dictType dict;
pthread_mutex_t mutex_;
}
Here would like to know.What this class actually intended for?
What is the flaw in the class & what is the fix?
How to improve the perfomance in the concurrent environment,or how to
better perfomance.
what will be the ideal test which can demonstrate perfomance
improvement in the concurrent environment
{
public :
Dictionary()
{
pthread_mutex_init(&mutex_,0)
}
virtual ~Dictionary()
{
pthread_mutex_destroy(&mutex_);
}
std::String transalate(std::string word) throw (std::string)
{
pthread_mutex_lock(&mutex_);
if (dict.find(word) == dict.end())
{
throw std::string(word + "not found");
}
std::string transalation = dict[MH:word];
pthread_mutex_unlock(&mutex_);
return transalation;
}
void addToDictionary (std::string word,std::string
transalation) throw (std::string)
{
pthread_mutex_lock(&mutex_);
if (dict.find(word)!=dict.end())
{
throw std::string(word + "already exits");
}
dict[MH:word]=transalation;
pthread_mutex_unlock(&mutex_);
}
private:
typedef std::map<std::string,std ::string>dictType;
dictType dict;
pthread_mutex_t mutex_;
}
Here would like to know.What this class actually intended for?
What is the flaw in the class & what is the fix?
How to improve the perfomance in the concurrent environment,or how to
better perfomance.
what will be the ideal test which can demonstrate perfomance
improvement in the concurrent environment