[prev in list] [next in list] [prev in thread] [next in thread] 

List:       semsdev
Subject:    Re: [Semsdev] singleton.h
From:       Szokovacs Robert <robert.szokovacs () gamma ! co ! uk>
Date:       2012-08-09 15:47:11
Message-ID: 5023DB7F.2080806 () gamma ! co ! uk
[Download RAW message or body]

On 09/08/12 16:45, Stefan Sayer wrote:
> Hi,
>
> o Szokovacs Robert on 08/08/2012 05:35 PM:
>> Hi,
>>
>> While reading singleton.h, I noticed that instance() copies the
>> pointer before returning it.
>> I could not prove to myself that
>>
>>    static singleton<T>* instance()
>>    {
>>      _inst_m.lock();
>>      if(!_instance) {
>>        _instance = new singleton<T>();
>>      }
>>
>>      _inst_m.unlock();
>>
>>      return _instance;
>>    }
>>
>> is wrong. What do I miss?
>
> it's the same, especially as the instance is created only once, so
> whether the function result is assigned inside or outside the
> mutex-protected block does not matter.

So, why not save the extra assignment then?

br

Szo
_______________________________________________
Semsdev mailing list
Semsdev@lists.iptel.org
http://lists.iptel.org/mailman/listinfo/semsdev
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic