Re: [eigen] Help on solving a race condition
• To: eigen <eigen@xxxxxxxxxxxxxxxxxxx>
• Subject: Re: [eigen] Help on solving a race condition
• From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
• Date: Fri, 8 Jun 2012 15:26:38 +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=dafOaHe6fDMCufCnOq4A+WQh6yNo0ynZLP4uOa1tpbI=; b=ikUohXlIXlThWD4hLQ6uomUgTeluNrnPESfkiotjN1c/j/z2FgG481YA3KDawDxE2P vxVlJjoGgYJ8V8CKAnybSdi/ZFvWE5sR+qiX8s5iZZUphlsTKtCA9PfyN1G4tAUXrCAq W67kqAyLXE+wvBHrHM4olRebwjzkIK7u1KuwSMDy35Rhe38Nrp/5m+XjkUzgU/OnkwMZ I29Nb3upvJGx9TVRKKyyCsyhlkUImZj0eYfyciCWeKoemRqM9jkeWxxl2H4bD8YzfKkZ oaVlPAAQ8ggJzD+d5wZW9iLMj8nhCFj5r5ENTWpfUMFq4ZR+YWpAb92KJWY3DQGOJtUU ziSg==

```OK, sorry my naivety, this is well explained here:

http://blogs.msdn.com/b/oldnewthing/archive/2004/03/08/85901.aspx

still looking for an elegant solution though.

gael

On Fri, Jun 8, 2012 at 3:12 PM, Gael Guennebaud
<gael.guennebaud@xxxxxxxxx> wrote:
> Hi,
>
> I'm looking for some help on understanding how the following piece of
> code in Eigen can lead to a race condition when the function
> manage_caching_sizes is called from different threads:
>
>
> inline std::ptrdiff_t manage_caching_sizes_helper(std::ptrdiff_t a,
> std::ptrdiff_t b)
> {
>  return a<=0 ? b : a;
> }
>
> inline void manage_caching_sizes(Action action, std::ptrdiff_t* l1=0,
> std::ptrdiff_t* l2=0)
> {
>  static std::ptrdiff_t m_l1CacheSize =
> manage_caching_sizes_helper(queryL1CacheSize(),8 * 1024);
>  static std::ptrdiff_t m_l2CacheSize =
> manage_caching_sizes_helper(queryTopLevelCacheSize(),1*1024*1024);
>  ...
> }
>
>
> During it's first call, this function computes and store the cache sizes.
>
> I would like to find a solution that avoids making the static variable
> "thread private" as suggested there: