|
Boost : |
Subject: Re: [boost] [any] new version
From: Nevin Liber (nevin_at_[hidden])
Date: 2011-09-02 13:44:24
On 2 September 2011 11:01, Ilya Bobir <ilya.bobir_at_[hidden]> wrote:
>> unsigned int next_id()
>> {
>> static unsigned int previous_id = 0; //0 is not assigned to a type
>>
>> ++previous_id;
>> return previous_id;
>> }
>>
>> [...]
>
> Would not this be non-thread safe?
That's the second problem that has to be tackled with this code.
Would this work:
unsigned next_id()
{
static std::atomic<unsigned> previous_id;
return ++previous_id;
}
-- Nevin ":-)" Liber <mailto:nevin_at_[hidden]> (847) 691-1404
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk