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: Samuel Thibault (samuel.thibault_at_[hidden])
Date: 2011-02-18 04:10:16


Brice Goglin, le Fri 18 Feb 2011 07:24:20 +0100, a écrit :
> 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?

Not even in C99.

Samuel