[Asterisk-Dev] Re: [Asterisk-cvs] asterisk/include/asterisk module.h, 1.18, 1.19

Slav Klenov slav at securax.org
Fri Jun 24 07:47:32 MST 2005


Well, it sounds reasonable. I just wanted to be sure about this.

Thanks for the reply

Slav


Kevin P. Fleming wrote:

> Slav Klenov wrote:
>
>> Is it guaranteed that the res = localusecnt assignement, without 
>> holding a lock,
>> can be done safely, without any possibility of damaging res? I'm not 
>> sure if this
>> can be considered as an atomic operation.
>
>
> What does 'damaging res mean' in this context?
>
> On all modern platforms (i.e. anything with a word size of 32 bits or 
> larger), as long as the int variables involved are aligned on their 
> natural boundaries (not in a 'packed' structure), then reading or 
> writing (but _NOT_ read/modify/write) of them is always an atomic 
> operation. There is no possibility for part of the int to be written 
> and then the remainder written later.
>
> In this code, 'res' does not need to be protected, only the read from 
> 'usecnt', since 'res' is not a shared variable.
> _______________________________________________
> Asterisk-Dev mailing list
> Asterisk-Dev at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-dev
> To UNSUBSCRIBE or update options visit:
>   http://lists.digium.com/mailman/listinfo/asterisk-dev





More information about the asterisk-dev mailing list