Re: [eigen] Help on solving a race condition |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Help on solving a race condition
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Fri, 15 Jun 2012 14:14:57 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=TBzX9q8dll8PrcB+inznlZjxFLYPiebfDG1GgyXUgsE=; b=aOdUD0nSaZ8k0XBS/4trtEZuJotsSL5bNe/hw8DT/QZhJHAWomGF0J/6NoIxO99KsH 4dGsuVVV/O0ZP5F20WN8G5HfIn4RzqDxJOamRAYWN6n8ZNC2i8u5jMYd1UQwhBG3QqkW 67zDG+Rcrewtmwbi8H2IBPcvKiOucu5pKGzUMXPXvbFj7SdJM/V9CAnH7QTO6Yg/j9N5 oLiy/9UCc8bXPk3MW6deKU3zYcHtW0jiiLX7y3v0trImcSHhvHZq6eo42NutMnhr5+26 O14y+zVyeJnnqLe1lVmBM5s1gyib9omGp3yiMbyHtb0ypkW1YZAcU7q2KmEv9ZPYWN5H FlEQ==
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
>
>