2012-07-03 54 views
0

「在此平臺上未實現64位NoBarrier_Store()」 我在win7上與vs2005一起使用tcmalloc。 在我的應用程序中有兩個線程,一個是malloc(),另一個是free(),當我的應用程序啓動時,tcmalloc會打印此文件。調試後,我發現以下functon無法在_WIN32上工作,64位NoBarrier_Store()未在此平臺上實現

// Return a suggested delay in nanoseconds for iteration number "loop" 
static int SuggestedDelayNS(int loop) { 
    // Weak pseudo-random number generator to get some spread between threads 
    // when many are spinning. 
    static base::subtle::Atomic64 rand; 
    uint64 r = base::subtle::NoBarrier_Load(&rand); 
    r = 0x5deece66dLL * r + 0xb; // numbers from nrand48() 
    base::subtle::NoBarrier_Store(&rand, r); 

    r <<= 16; // 48-bit random number now in top 48-bits. 
    if (loop < 0 || loop > 32) { // limit loop to 0..32 
    loop = 32; 
    } 
    // loop>>3 cannot exceed 4 because loop cannot exceed 32. 
    // Select top 20..24 bits of lower 48 bits, 
    // giving approximately 0ms to 16ms. 
    // Mean is exponential in loop for first 32 iterations, then 8ms. 
    // The futex path multiplies this by 16, since we expect explicit wakeups 
    // almost always on that path. 
    return r >> (44 - (loop >> 3)); 
} 

我想知道如何避免這在win32上。非常感謝。

回答

1

它似乎是使用原子加載和存儲沒有內存障礙。在某些多CPU系統上可能會使這項工作更快一點。

在x86上,我們沒有這些類型的操作。系統中的其他內核始終可以看到加載和存儲。緩存同步在硬件中實現,不能由程序控制。

也許使用的Atomic庫有沒有NoBarrier前綴的加載和存儲操作?改用這些。

+0

是的,你是對的。 tcmalloc現在已經更新了svn。謝謝! – user1497861

相關問題