Re: [eigen] Help on solving a race condition

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


Hi,

yes I already had a look at a few atomic libs, including atomic-ops,
but we don't have the same definition of portable. So clearly some
architectures/systems will require a manual initialization.
Nevertheless, we could still enable atomic ops for the few systems for
which we are sure about the results:

Windows-x86-MSVC -> _InterlockedCompareExchange intrinsic
Linux/windows-x86-ICC-GCC -> __sync_val_compare_and_swap intrinsic.

That probably already cover 95% of the use cases, so why not. I
already have a version doing so.

Using C++11 atomics is dangerous because currently the compilers
defines __cplusplus >= 201103L even though they don't support all
c++11 features. For instance, atomic are supported by clang only from
the 3.1 version. So in addition to checking for __cplusplus >=
201103L, we also have to check the compiler name and version, and
that's how the nightmare starts...

gael

On Fri, Jun 15, 2012 at 1:23 PM, Ilja Honkonen
<ilja.honkonen@xxxxxxxxxxx> wrote:
>>>> 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.
>>
>> You could do manually using bitfield or even simplier, if you could
>> guaranted that int is initialised to zero at init you test if it is
>> equal to zero, and write if not equal.Or if you are worried about
>> this, you could add a depend on libatomic see
>> http://packages.qa.debian.org/liba/libatomic-ops.html
>> And it is portable and it will not add a depend if you use thread,
>> because pthread and gcc use it internally.
>
>
> The atomic stuff in C++11 is (or will be) even more portable:
> http://en.cppreference.com/w/cpp/atomic
>
> Ilja
>
>



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