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: Wed, 13 Jun 2012 22:57:01 +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=gMQF96YThxMOuIayLqhoz5L7bSiPJhC9lCqnpqPUHyk=; b=LFCKU+V3lUnkhInA1eV0cmx2P0mTUdsQMvspD8O46k/7VsqL2sdhAOKGgGg72bDeLT NJi+KT8B16JsX7GuRZDDxOhHrIXVdXrY/a+47q2BIlYTiXKQ+9MiRoM10x4F5qDSdofs OADQOprdoWrzk/RzefiTWvJ0H55C+8AWGumM7Hnnqsz9mL3HNgzd21j7KMtfPw7lNH27 rBAsen54tyAj9FrQbInnnrsCO2sENzTQRaOPWP9F6NhXXymoqzVGhDAiY2oA9aQ3t+BC Q/uekTeGvdqE4dGgPjpZ4fdBfsZffuuwyd5aRI19dvxFV1hTWHuN9euJbOAf3D1EmAfT /vpQ==
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