我设计了一些类。就像这样:
- 该类
ClientEntity
可以有多个实例。 - 创建
ClientEntity
对象时,它不会被修改,所以我不使用互斥锁。 ClientEntity
对象可以在不同的线程之间访问。ClientEntity
对象在收到一些退出命令时将被销毁。ClientEntity
某些线程可能会访问对象。
我怎样才能安全地销毁这个对象?
class ClientEntity
{
public:
conference_info & conf_info (){return conf_info_;}
void conf_info(const conference_info &ci){conf_info_ = ci;}
user_info & usr_info(){return usr_info_;}
void usr_info(const user_info &ui){usr_info_ = ui;}
private:
web_conf_info *wci_;
user_info usr_info_;
conference_info conf_info_;
// .....
};
class user_info
{
public:
user_info & operator = (const user_info &ui)
{
if (this != &ui){
user_id = ui.user_id;
user_name = ui.user_name;
user_role = ui.user_role;
}
return *this;
}
public:
int user_id;
int user_role;
std::string user_name;
};
class conference_info
{
public:
conference_info & operator = (const conference_info &conf)
{
if (this != &conf){
conf_id = conf.conf_id;
dtsip_list = conf.dtsip_list;
ctsip_list = conf.ctsip_list;
}
return *this;
}
public:
int conf_id;
std::list<std::string> dtsip_list;
std::list<std::string> ctsip_list;
};