| 54 | } |
| 55 | |
| 56 | virtual void test() |
| 57 | { |
| 58 | size_t const nThreadCount = s_nThreadCount; |
| 59 | size_t const nTotalPush = m_nTotalPushCount; |
| 60 | |
| 61 | m_arrLastRead.resize( nThreadCount, 0 ); |
| 62 | m_arrPopCountPerThread.resize( nThreadCount, 0 ); |
| 63 | |
| 64 | value_type node; |
| 65 | |
| 66 | while ( m_nPushCount < nTotalPush ) { |
| 67 | if ( ( std::rand() & 3) != 3 ) { |
| 68 | node.nThread = id(); |
| 69 | node.nNo = ++m_nPushCount; |
| 70 | if ( !m_Queue.push( node )) { |
| 71 | ++m_nPushError; |
| 72 | --m_nPushCount; |
| 73 | } |
| 74 | } |
| 75 | else |
| 76 | pop( nThreadCount ); |
| 77 | } |
| 78 | |
| 79 | s_nProducerCount.fetch_sub( 1, std::memory_order_relaxed ); |
| 80 | |
| 81 | while ( !m_Queue.empty() || s_nProducerCount.load( std::memory_order_relaxed ) != 0 ) |
| 82 | pop( nThreadCount ); |
| 83 | } |
| 84 | |
| 85 | bool pop( size_t nThreadCount ) |
| 86 | { |