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: Bastien ROUCARIES <roucaries.bastien@xxxxxxxxx>
- Date: Fri, 15 Jun 2012 13:15:08 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=Oy7rN8jxQ/abV52+v5cKAUEyqjzqWGAuyLkws3E7rtE=; b=0k6FYm0QUbfrLcShczi86qUqkDJALTIY3J1jarWI4tLoAtilbCHZdsPxiwLcnwn5lu sspL3KdGgPFfJIaBCzsY9TTk1MRU5GFEXJ7Bu5o7M+ALBCVm4TH4F7jq5Zh2sqtZA7hE KwrAko5kBgvFNCOGRjVCIXegu2qgriXJneUiSo5NnFHEc3h73+N5qYdpAoXSNXivbtN7 usEBuyPMRN/b54+fVRJ78eRMHTtzVD8lh3EOl/zcAwLJBJBN3YMAmppoTlpG+B9RQCJb dCwfgISWSkftGvVY+n5ambK9B5rKBP/E6nhbd+kSORduDwdNpJT3kNTRn+MLRIx+g+7+ 12Eg==
On Wed, Jun 13, 2012 at 10:57 PM, Gael Guennebaud
<gael.guennebaud@xxxxxxxxx> wrote:
> 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.
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.
Bastien
>
> gael
>
>