[PATCH 1/2] add atomc_sub and atomic_compare_exchange into smpatomic08

Deng Hengyi wei.a.yang at gmail.com
Sun Sep 1 02:19:41 UTC 2013


在 2013-8-31,下午3:22,Sebastian Huber <sebastian.huber at embedded-brains.de> 写道:

> On 2013-08-31 03:49, WeiY wrote:
>> +  while (!stop(ctx)) {
>> +    while (_Atomic_Compare_exchange_uint(&ctx->global_swap, &ctx->global_swap_t,
>> +      worker_index, ATOMIC_ORDER_ACQUIRE, ATOMIC_ORDER_RELEASE)) {
>> +      /* Wait */
>> +    }
>> +    ++counter;
>> +    ++ctx->flag_counter;
>> +    ctx->global_swap_t = worker_index;
>> +  }
> 
> This doesn't work since ctx->global_swap_t is a normal variable. Also the failure memory order is wrong.  You try to implement a mutex here.  In case the compare exchange failed, then we try it again thus we don't care about a particular memory order here (ATOMIC_ORDER_RELAXED).  The success order is all right, since this is the mutex acquire path.
Right, the failure memory order should use ATOMIC_ORDER_RELAXED, because when compare exchange failed the thread of loading does not have any dependence on other threads.
I think if i add a memory_barrier after 'ctx->global_swap_t = worker_index;' it will be ok. Am i right?
> 
> 
> The init and fini handler for the test case don't fit to the body.
Yeah,  
1. I should add add ctx->flag_counter = 0 to init handler.
2. In the fink handler i should also use flag_counter instead of global_uint.

> -- 
> Sebastian Huber, embedded brains GmbH
> 
> Address : Dornierstr. 4, D-82178 Puchheim, Germany
> Phone   : +49 89 189 47 41-16
> Fax     : +49 89 189 47 41-09
> E-Mail  : sebastian.huber at embedded-brains.de
> PGP     : Public key available on request.
> 
> Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
> 





More information about the devel mailing list