Open MPI logo

Hardware Locality Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Hardware Locality Development mailing list

Subject: Re: [hwloc-devel] The de-C99 of hwloc
From: Brice Goglin (Brice.Goglin_at_[hidden])
Date: 2011-02-18 01:24:03


Le 18/02/2011 00:53, Samuel Thibault a écrit :
>> + /* Setup ordering arrays */
>> + if (!orders_initialized) {
>> + obj_type_order[HWLOC_OBJ_SYSTEM] = 0;
>> + obj_type_order[HWLOC_OBJ_MACHINE] = 1;
>> + obj_type_order[HWLOC_OBJ_GROUP] = 2;
>> + obj_type_order[HWLOC_OBJ_NODE] = 3;
>> + obj_type_order[HWLOC_OBJ_SOCKET] = 4;
>> + obj_type_order[HWLOC_OBJ_CACHE] = 5;
>> + obj_type_order[HWLOC_OBJ_CORE] = 6;
>> + obj_type_order[HWLOC_OBJ_PU] = 7;
>> + obj_type_order[HWLOC_OBJ_MISC] = 8;
>> +
>> + orders_initialized = 1;
>> + }
>>
> This is not actually thread safe. This needs a CPU write memory barrier
> between the last obj_type_order[] array write and the orders_initialized
> write, and a read barrier after orders_initialized is read as being
> 1, to make sure that a cpu seeing orders_initialized as 1 will always
> also see the values in obj_type_order. A simpler way is to use
> pthread_once().
>

Is there no portable way to define a library _init function? The above
should not be in the topology init routine.

Brice