Re: [eigen] Help on solving a race condition

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


On Mon, Jun 11, 2012 at 11:02 PM, Bastien ROUCARIES
<roucaries.bastien@xxxxxxxxx> wrote:
> On Mon, Jun 11, 2012 at 10:00 PM, Gael Guennebaud
> <gael.guennebaud@xxxxxxxxx> wrote:
>> Thanks a lot, that's the kind of explanations I expected.
>>
>>
>> So I'm afraid the only truly portable and robust solution will be to
>> add an initialize function.
>
> No please do not do that. Thread and tls function are pretty portable
> (see below) and moreover c++11 need it in order to implement some
> construct.
>
> And please prefer GNUC solution that use the tls register that is a
> free to use if your binary use dso.

Well that might be true very recent compilers, for instance I cannot
find any simple solution for default's mac compiler. Same for clang,
and I haven't tried yet ARM platforms... So clearly it's going to be a
real mess with tons of bug reports of users who don't even care about
multi-threading...

> you could fallback to static constructor if you want but I believe in
> pratice it will be not used (local thread is used by gnulib and well
> tested on a variety of platform).
>
> If you want to use volatile notice that written to a volatile int is
> safe a least in C language (therefore extern C), because int read is
> in pratice atomic and if not it will break a lot of code. Thus a
> portable solution will be to compute your value in a tempory struct
> union
> {
>  struct {
>  char  m_l1CacheSize;
>  char m_l2CacheSize;
>  char power;
>  char initialized;
>  };
>  int word;
> }

The problem with that solution is that's not possible to initialize
the 'initialized' or whole 'word' variable because they are part of a
union.


gael



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/