How can I destroy a shared object safely in a multi-threaded program?
<p>I designed some class. It's like this:</p>

<ol>
<li>The class <code>ClientEntity</code> can have multiple instances.</li>
<li>When a <code>ClientEntity</code> object is created, it will not be modified, so I don't use the mutex.</li>
<li><code>ClientEntity</code> objects can be accessed between different threads.</li>
<li><code>ClientEntity</code> objects will be destroyed when they receive some quit commands.</li>
<li><code>ClientEntity</code> objects may be accessed by some threads.</li>
</ol>

<p><strong>How can I destroy this object safely?</strong></p>

<pre><code>class ClientEntity
{
public:
    conference_info &amp; conf_info (){return conf_info_;}
    void conf_info(const conference_info &amp;ci){conf_info_ = ci;}

    user_info &amp; usr_info(){return usr_info_;}
    void usr_info(const user_info &amp;ui){usr_info_ = ui;}

private:
    web_conf_info *wci_;
    user_info usr_info_;
    conference_info conf_info_;

    // .....
};

class user_info
{
public:
    user_info &amp; operator = (const user_info &amp;ui)
    {   
        if (this != &amp;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 &amp; operator = (const conference_info &amp;conf)
    {   
        if (this != &amp;conf){
            conf_id = conf.conf_id;
            dtsip_list = conf.dtsip_list;
            ctsip_list = conf.ctsip_list;
        }   

        return *this;
    }
public:
    int conf_id;
    std::list&lt;std::string&gt; dtsip_list;
    std::list&lt;std::string&gt; ctsip_list;
};
</code></pre>
