On 04/05/2017 13:15, Stefan Hajnoczi wrote:
> On Thu, Apr 20, 2017 at 02:00:42PM +0200, Paolo Bonzini wrote:
>>  void bdrv_disable_copy_on_read(BlockDriverState *bs)
>>  {
>> -    assert(bs->copy_on_read > 0);
>> -    bs->copy_on_read--;
>> +    assert(atomic_read(&bs->copy_on_read) > 0);
>> +    atomic_dec(&bs->copy_on_read);
>>  }
> 
> To make this truly thread-safe:
> 
>   old = atomic_dec_fetch(&bs->copy_on_read);
>   assert(old > 0);

Good point.  It feels wrong to assert after the fact, but then so does
making the assertion not quite thread safe.

Paolo

Reply via email to