For example, I create a singleTon lock class. Then I use the locker whatever I want, for example another singleTon
class SIN
{
public:
static SIN& getSIN()
{
static SIN *sin = new SIN;
return *sin;
}
void insertMap(const int& id,const string& str)
{
locker::getLocker().lock();
subMap[id] = str;
locker::getLocker().unlock();
return;
}
string getStr(const int& id)
{
string str = "";
locker::getLocker().lock();
if(subMap.find(id) != subMap.end()){
str = subMap[id];
}
locker::getLocker().unlock();
return str;
}
private:
SIN(){}
SIN(const SIN&) = delete;
SIN& operator=(const SIN&) = delete;
private:
map<int,string> subMap;
}
I don't find this usage in network, will there be any potential problems during using?
Aucun commentaire:
Enregistrer un commentaire