movable exempt_ptr: SkipList
[libcds.git] / tests / unit / set2 / set_delodd.cpp
1 //$$CDS-header$$
2
3 #include "cppunit/thread.h"
4 #include "set2/set_types.h"
5 #include <algorithm> // random_shuffle
6
7 namespace set2 {
8
9 #    define TEST_SET(X)         void X() { test<SetTypes<key_type, value_type>::X >()    ; }
10 #    define TEST_SET_EXTRACT(X) void X() { test_extract<SetTypes<key_type, value_type>::X >()    ; }
11 #    define TEST_SET_NOLF(X)    void X() { test_nolf<SetTypes<key_type, value_type>::X >()    ; }
12 #    define TEST_SET_NOLF_EXTRACT(X)    void X() { test_nolf_extract<SetTypes<key_type, value_type>::X >()    ; }
13
14     namespace {
15         static size_t  c_nSetSize = 1000000         ;  // max set size
16         static size_t  c_nInsThreadCount = 4        ;  // insert thread count
17         static size_t  c_nDelThreadCount = 4        ;  // delete thread count
18         static size_t  c_nExtractThreadCount = 4    ;  // extract thread count
19         static size_t  c_nMaxLoadFactor = 8         ;  // maximum load factor
20         static bool    c_bPrintGCState = true;
21     }
22
23     namespace {
24         struct key_thread
25         {
26             size_t  nKey;
27             size_t  nThread;
28
29             key_thread( size_t key, size_t threadNo )
30                 : nKey( key )
31                 , nThread( threadNo )
32             {}
33
34             key_thread()
35             {}
36         };
37
38         typedef SetTypes<key_thread, size_t>::key_val     key_value_pair;
39     }
40
41     template <>
42     struct cmp<key_thread> {
43         int operator ()(key_thread const& k1, key_thread const& k2) const
44         {
45             if ( k1.nKey < k2.nKey )
46                 return -1;
47             if ( k1.nKey > k2.nKey )
48                 return 1;
49             if ( k1.nThread < k2.nThread )
50                 return -1;
51             if ( k1.nThread > k2.nThread )
52                 return 1;
53             return 0;
54         }
55         int operator ()(key_thread const& k1, size_t k2) const
56         {
57             if ( k1.nKey < k2 )
58                 return -1;
59             if ( k1.nKey > k2 )
60                 return 1;
61             return 0;
62         }
63         int operator ()(size_t k1, key_thread const& k2) const
64         {
65             if ( k1 < k2.nKey )
66                 return -1;
67             if ( k1 > k2.nKey )
68                 return 1;
69             return 0;
70         }
71     };
72
73 } // namespace set2
74
75 namespace std {
76     template <>
77     struct less<set2::key_thread>
78     {
79         bool operator()(set2::key_thread const& k1, set2::key_thread const& k2) const
80         {
81             if ( k1.nKey <= k2.nKey )
82                 return k1.nKey < k2.nKey || k1.nThread < k2.nThread;
83             return false;
84         }
85     };
86
87     template <>
88     struct hash<set2::key_thread>
89     {
90         typedef size_t              result_type;
91         typedef set2::key_thread    argument_type;
92
93         size_t operator()( set2::key_thread const& k ) const
94         {
95             return std::hash<size_t>()(k.nKey);
96         }
97         size_t operator()( size_t k ) const
98         {
99             return std::hash<size_t>()(k);
100         }
101     };
102
103 } // namespace std
104
105 namespace boost {
106     inline size_t hash_value( set2::key_thread const& k )
107     {
108         return std::hash<size_t>()( k.nKey );
109     }
110
111     template <>
112     struct hash<set2::key_thread>
113     {
114         typedef size_t              result_type;
115         typedef set2::key_thread    argument_type;
116
117         size_t operator()(set2::key_thread const& k) const
118         {
119             return boost::hash<size_t>()( k.nKey );
120         }
121         size_t operator()(size_t k) const
122         {
123             return boost::hash<size_t>()( k );
124         }
125     };
126 } // namespace boost
127
128 namespace set2 {
129
130     template <typename Set>
131     static inline void check_before_clear( Set& s )
132     {}
133
134     template <typename GC, typename Key, typename T, typename Traits>
135     static inline void check_before_clear( cds::container::EllenBinTreeSet<GC, Key, T, Traits>& s )
136     {
137         CPPUNIT_CHECK_CURRENT( s.check_consistency() );
138     }
139
140     class Set_DelOdd: public CppUnitMini::TestCase
141     {
142         std::vector<size_t>     m_arrData;
143
144     protected:
145         typedef key_thread  key_type;
146         typedef size_t      value_type;
147
148         atomics::atomic<size_t>      m_nInsThreadCount;
149
150         // Inserts keys from [0..N)
151         template <class Set>
152         class InsertThread: public CppUnitMini::TestThread
153         {
154             Set&     m_Set;
155
156             virtual InsertThread *    clone()
157             {
158                 return new InsertThread( *this );
159             }
160
161             struct ensure_func
162             {
163                 template <typename Q>
164                 void operator()( bool bNew, key_value_pair const&, Q const& )
165                 {}
166             };
167         public:
168             size_t  m_nInsertSuccess;
169             size_t  m_nInsertFailed;
170
171         public:
172             InsertThread( CppUnitMini::ThreadPool& pool, Set& rMap )
173                 : CppUnitMini::TestThread( pool )
174                 , m_Set( rMap )
175             {}
176             InsertThread( InsertThread& src )
177                 : CppUnitMini::TestThread( src )
178                 , m_Set( src.m_Set )
179             {}
180
181             Set_DelOdd&  getTest()
182             {
183                 return reinterpret_cast<Set_DelOdd&>( m_Pool.m_Test );
184             }
185
186             virtual void init() { cds::threading::Manager::attachThread()   ; }
187             virtual void fini() { cds::threading::Manager::detachThread()   ; }
188
189             virtual void test()
190             {
191                 Set& rSet = m_Set;
192
193                 m_nInsertSuccess =
194                     m_nInsertFailed = 0;
195
196                 std::vector<size_t>& arrData = getTest().m_arrData;
197                 for ( size_t i = 0; i < arrData.size(); ++i ) {
198                     if ( rSet.insert( key_type( arrData[i], m_nThreadNo )))
199                         ++m_nInsertSuccess;
200                     else
201                         ++m_nInsertFailed;
202                 }
203
204                 ensure_func f;
205                 for ( size_t i = arrData.size() - 1; i > 0; --i ) {
206                     if ( arrData[i] & 1 ) {
207                         rSet.ensure( key_type( arrData[i], m_nThreadNo ), f );
208                     }
209                 }
210
211                 getTest().m_nInsThreadCount.fetch_sub( 1, atomics::memory_order_release );
212             }
213         };
214
215         struct key_equal {
216             bool operator()( key_type const& k1, key_type const& k2 ) const
217             {
218                 return k1.nKey == k2.nKey;
219             }
220             bool operator()( size_t k1, key_type const& k2 ) const
221             {
222                 return k1 == k2.nKey;
223             }
224             bool operator()( key_type const& k1, size_t k2 ) const
225             {
226                 return k1.nKey == k2;
227             }
228             bool operator ()( key_value_pair const& k1, key_value_pair const& k2 ) const
229             {
230                 return operator()( k1.key, k2.key );
231             }
232             bool operator ()( key_value_pair const& k1, key_type const& k2 ) const
233             {
234                 return operator()( k1.key, k2 );
235             }
236             bool operator ()( key_type const& k1, key_value_pair const& k2 ) const
237             {
238                 return operator()( k1, k2.key );
239             }
240             bool operator ()( key_value_pair const& k1, size_t k2 ) const
241             {
242                 return operator()( k1.key, k2 );
243             }
244             bool operator ()( size_t k1, key_value_pair const& k2 ) const
245             {
246                 return operator()( k1, k2.key );
247             }
248         };
249
250         struct key_less {
251             bool operator()( key_type const& k1, key_type const& k2 ) const
252             {
253                 return k1.nKey < k2.nKey;
254             }
255             bool operator()( size_t k1, key_type const& k2 ) const
256             {
257                 return k1 < k2.nKey;
258             }
259             bool operator()( key_type const& k1, size_t k2 ) const
260             {
261                 return k1.nKey < k2;
262             }
263             bool operator ()( key_value_pair const& k1, key_value_pair const& k2 ) const
264             {
265                 return operator()( k1.key, k2.key );
266             }
267             bool operator ()( key_value_pair const& k1, key_type const& k2 ) const
268             {
269                 return operator()( k1.key, k2 );
270             }
271             bool operator ()( key_type const& k1, key_value_pair const& k2 ) const
272             {
273                 return operator()( k1, k2.key );
274             }
275             bool operator ()( key_value_pair const& k1, size_t k2 ) const
276             {
277                 return operator()( k1.key, k2 );
278             }
279             bool operator ()( size_t k1, key_value_pair const& k2 ) const
280             {
281                 return operator()( k1, k2.key );
282             }
283
284             typedef key_equal   equal_to;
285         };
286
287         // Deletes odd keys from [0..N)
288         template <class Set>
289         class DeleteThread: public CppUnitMini::TestThread
290         {
291             Set&     m_Set;
292
293             virtual DeleteThread *    clone()
294             {
295                 return new DeleteThread( *this );
296             }
297         public:
298             size_t  m_nDeleteSuccess;
299             size_t  m_nDeleteFailed;
300
301         public:
302             DeleteThread( CppUnitMini::ThreadPool& pool, Set& rMap )
303                 : CppUnitMini::TestThread( pool )
304                 , m_Set( rMap )
305             {}
306             DeleteThread( DeleteThread& src )
307                 : CppUnitMini::TestThread( src )
308                 , m_Set( src.m_Set )
309             {}
310
311             Set_DelOdd&  getTest()
312             {
313                 return reinterpret_cast<Set_DelOdd&>( m_Pool.m_Test );
314             }
315
316             virtual void init() { cds::threading::Manager::attachThread()   ; }
317             virtual void fini() { cds::threading::Manager::detachThread()   ; }
318
319             virtual void test()
320             {
321                 Set& rSet = m_Set;
322
323                 m_nDeleteSuccess =
324                     m_nDeleteFailed = 0;
325
326                 std::vector<size_t>& arrData = getTest().m_arrData;
327                 if ( m_nThreadNo & 1 ) {
328                     for ( size_t k = 0; k < c_nInsThreadCount; ++k ) {
329                         for ( size_t i = 0; i < arrData.size(); ++i ) {
330                             if ( arrData[i] & 1 ) {
331                                 if ( rSet.erase_with( arrData[i], key_less() ))
332                                     ++m_nDeleteSuccess;
333                                 else
334                                     ++m_nDeleteFailed;
335                             }
336                         }
337                         if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 )
338                             break;
339                     }
340                 }
341                 else {
342                     for ( size_t k = 0; k < c_nInsThreadCount; ++k ) {
343                         for ( size_t i = arrData.size() - 1; i > 0; --i ) {
344                             if ( arrData[i] & 1 ) {
345                                 if ( rSet.erase_with( arrData[i], key_less() ))
346                                     ++m_nDeleteSuccess;
347                                 else
348                                     ++m_nDeleteFailed;
349                             }
350                         }
351                         if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 )
352                             break;
353                     }
354                 }
355             }
356         };
357
358         // Extracts odd keys from [0..N)
359         template <typename GC, class Set>
360         class ExtractThread: public CppUnitMini::TestThread
361         {
362             Set&     m_Set;
363
364             virtual ExtractThread *    clone()
365             {
366                 return new ExtractThread( *this );
367             }
368         public:
369             size_t  m_nExtractSuccess;
370             size_t  m_nExtractFailed;
371
372         public:
373             ExtractThread( CppUnitMini::ThreadPool& pool, Set& rMap )
374                 : CppUnitMini::TestThread( pool )
375                 , m_Set( rMap )
376             {}
377             ExtractThread( ExtractThread& src )
378                 : CppUnitMini::TestThread( src )
379                 , m_Set( src.m_Set )
380             {}
381
382             Set_DelOdd&  getTest()
383             {
384                 return reinterpret_cast<Set_DelOdd&>( m_Pool.m_Test );
385             }
386
387             virtual void init() { cds::threading::Manager::attachThread()   ; }
388             virtual void fini() { cds::threading::Manager::detachThread()   ; }
389
390             virtual void test()
391             {
392                 Set& rSet = m_Set;
393
394                 m_nExtractSuccess =
395                     m_nExtractFailed = 0;
396
397                 typename Set::guarded_ptr gp;
398
399                 std::vector<size_t>& arrData = getTest().m_arrData;
400                 if ( m_nThreadNo & 1 ) {
401                     for ( size_t k = 0; k < c_nInsThreadCount; ++k ) {
402                         for ( size_t i = 0; i < arrData.size(); ++i ) {
403                             if ( arrData[i] & 1 ) {
404                                 if ( rSet.extract_with( gp, arrData[i], key_less() ))
405                                     ++m_nExtractSuccess;
406                                 else
407                                     ++m_nExtractFailed;
408                             }
409                         }
410                         if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 )
411                             break;
412                     }
413                 }
414                 else {
415                     for ( size_t k = 0; k < c_nInsThreadCount; ++k ) {
416                         for ( size_t i = arrData.size() - 1; i > 0; --i ) {
417                             if ( arrData[i] & 1 ) {
418                                 if ( rSet.extract_with( gp, arrData[i], key_less() ))
419                                     ++m_nExtractSuccess;
420                                 else
421                                     ++m_nExtractFailed;
422                             }
423                         }
424                         if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 )
425                             break;
426                     }
427                 }
428             }
429         };
430
431         template <typename RCU, class Set>
432         class ExtractThread< cds::urcu::gc<RCU>, Set >: public CppUnitMini::TestThread
433         {
434             Set&     m_Set;
435
436             virtual ExtractThread *    clone()
437             {
438                 return new ExtractThread( *this );
439             }
440         public:
441             size_t  m_nExtractSuccess;
442             size_t  m_nExtractFailed;
443
444         public:
445             ExtractThread( CppUnitMini::ThreadPool& pool, Set& rMap )
446                 : CppUnitMini::TestThread( pool )
447                 , m_Set( rMap )
448             {}
449             ExtractThread( ExtractThread& src )
450                 : CppUnitMini::TestThread( src )
451                 , m_Set( src.m_Set )
452             {}
453
454             Set_DelOdd&  getTest()
455             {
456                 return reinterpret_cast<Set_DelOdd&>( m_Pool.m_Test );
457             }
458
459             virtual void init() { cds::threading::Manager::attachThread()   ; }
460             virtual void fini() { cds::threading::Manager::detachThread()   ; }
461
462             virtual void test()
463             {
464                 Set& rSet = m_Set;
465
466                 m_nExtractSuccess =
467                     m_nExtractFailed = 0;
468
469                 typename Set::exempt_ptr xp;
470
471                 std::vector<size_t>& arrData = getTest().m_arrData;
472                 if ( m_nThreadNo & 1 ) {
473                     for ( size_t k = 0; k < c_nInsThreadCount; ++k ) {
474                         for ( size_t i = 0; i < arrData.size(); ++i ) {
475                             if ( arrData[i] & 1 ) {
476                                 if ( Set::c_bExtractLockExternal ) {
477                                     typename Set::rcu_lock l;
478                                     xp = rSet.extract_with( arrData[i], key_less() );
479                                     if ( xp )
480                                         ++m_nExtractSuccess;
481                                     else
482                                         ++m_nExtractFailed;
483                                 }
484                                 else {
485                                     xp = rSet.extract_with( arrData[i], key_less() );
486                                     if ( xp )
487                                         ++m_nExtractSuccess;
488                                     else
489                                         ++m_nExtractFailed;
490                                 }
491                                 xp.release();
492                             }
493                         }
494                         if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 )
495                             break;
496                     }
497                 }
498                 else {
499                     for ( size_t k = 0; k < c_nInsThreadCount; ++k ) {
500                         for ( size_t i = arrData.size() - 1; i > 0; --i ) {
501                             if ( arrData[i] & 1 ) {
502                                 if ( Set::c_bExtractLockExternal ) {
503                                     typename Set::rcu_lock l;
504                                     xp = rSet.extract_with( arrData[i], key_less() );
505                                     if ( xp )
506                                         ++m_nExtractSuccess;
507                                     else
508                                         ++m_nExtractFailed;
509                                 }
510                                 else {
511                                     xp = rSet.extract_with( arrData[i], key_less() );
512                                     if ( xp )
513                                         ++m_nExtractSuccess;
514                                     else
515                                         ++m_nExtractFailed;
516                                 }
517                                 xp.release();
518                             }
519                         }
520                         if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 )
521                             break;
522                     }
523                 }
524             }
525         };
526
527     protected:
528         template <class Set>
529         void do_test( size_t nLoadFactor )
530         {
531             Set  testSet( c_nSetSize, nLoadFactor );
532             do_test_with( testSet );
533             analyze( testSet );
534         }
535
536         template <class Set>
537         void do_test_extract( size_t nLoadFactor )
538         {
539             Set  testSet( c_nSetSize, nLoadFactor );
540             do_test_extract_with( testSet );
541             analyze( testSet );
542         }
543
544         template <class Set>
545         void do_test_with( Set& testSet )
546         {
547             typedef InsertThread<Set> insert_thread;
548             typedef DeleteThread<Set> delete_thread;
549
550             m_nInsThreadCount.store( c_nInsThreadCount, atomics::memory_order_release );
551
552             CppUnitMini::ThreadPool pool( *this );
553             pool.add( new insert_thread( pool, testSet ), c_nInsThreadCount );
554             pool.add( new delete_thread( pool, testSet ), c_nDelThreadCount ? c_nDelThreadCount : cds::OS::topology::processor_count());
555             pool.run();
556             CPPUNIT_MSG( "   Duration=" << pool.avgDuration() );
557
558             size_t nInsertSuccess = 0;
559             size_t nInsertFailed = 0;
560             size_t nDeleteSuccess = 0;
561             size_t nDeleteFailed = 0;
562             for ( CppUnitMini::ThreadPool::iterator it = pool.begin(); it != pool.end(); ++it ) {
563                 insert_thread * pThread = dynamic_cast<insert_thread *>( *it );
564                 if ( pThread ) {
565                     nInsertSuccess += pThread->m_nInsertSuccess;
566                     nInsertFailed += pThread->m_nInsertFailed;
567                 }
568                 else {
569                     delete_thread * p = static_cast<delete_thread *>( *it );
570                     nDeleteSuccess += p->m_nDeleteSuccess;
571                     nDeleteFailed += p->m_nDeleteFailed;
572                 }
573             }
574
575             CPPUNIT_CHECK( nInsertSuccess == c_nSetSize * c_nInsThreadCount );
576             CPPUNIT_CHECK( nInsertFailed == 0 );
577
578             CPPUNIT_MSG( "  Totals (success/failed): \n\t"
579                       << "      Insert=" << nInsertSuccess << '/' << nInsertFailed << "\n\t"
580                       << "      Delete=" << nDeleteSuccess << '/' << nDeleteFailed << "\n\t"
581             );
582         }
583
584         template <class Set>
585         void do_test_extract_with( Set& testSet )
586         {
587             typedef InsertThread<Set> insert_thread;
588             typedef DeleteThread<Set> delete_thread;
589             typedef ExtractThread< typename Set::gc, Set > extract_thread;
590
591             m_nInsThreadCount.store( c_nInsThreadCount, atomics::memory_order_release );
592
593             CppUnitMini::ThreadPool pool( *this );
594             pool.add( new insert_thread( pool, testSet ), c_nInsThreadCount );
595             if ( c_nDelThreadCount )
596                 pool.add( new delete_thread( pool, testSet ), c_nDelThreadCount );
597             if ( c_nExtractThreadCount )
598                 pool.add( new extract_thread( pool, testSet ), c_nExtractThreadCount );
599             pool.run();
600             CPPUNIT_MSG( "   Duration=" << pool.avgDuration() );
601
602             size_t nInsertSuccess = 0;
603             size_t nInsertFailed = 0;
604             size_t nDeleteSuccess = 0;
605             size_t nDeleteFailed = 0;
606             size_t nExtractSuccess = 0;
607             size_t nExtractFailed = 0;
608             for ( CppUnitMini::ThreadPool::iterator it = pool.begin(); it != pool.end(); ++it ) {
609                 insert_thread * pThread = dynamic_cast<insert_thread *>( *it );
610                 if ( pThread ) {
611                     nInsertSuccess += pThread->m_nInsertSuccess;
612                     nInsertFailed += pThread->m_nInsertFailed;
613                 }
614                 else {
615                     delete_thread * p = dynamic_cast<delete_thread *>( *it );
616                     if ( p ) {
617                         nDeleteSuccess += p->m_nDeleteSuccess;
618                         nDeleteFailed += p->m_nDeleteFailed;
619                     }
620                     else {
621                         extract_thread * pExt = dynamic_cast<extract_thread *>( *it );
622                         assert( pExt );
623                         nExtractSuccess += pExt->m_nExtractSuccess;
624                         nExtractFailed += pExt->m_nExtractFailed;
625                     }
626                 }
627             }
628
629             CPPUNIT_CHECK( nInsertSuccess == c_nSetSize * c_nInsThreadCount );
630             CPPUNIT_CHECK( nInsertFailed == 0 );
631
632             CPPUNIT_MSG( "  Totals (success/failed): \n\t"
633                 << "      Insert=" << nInsertSuccess << '/' << nInsertFailed << "\n\t"
634                 << "      Delete=" << nDeleteSuccess << '/' << nDeleteFailed << "\n\t"
635                 << "      Extract=" << nExtractSuccess << '/' << nExtractFailed << "\n\t"
636                 );
637         }
638
639         template <typename Set>
640         void analyze( Set& testSet )
641         {
642             // All even keys must be in the set
643             {
644                 CPPUNIT_MSG( "  Check even keys..." );
645                 size_t nErrorCount = 0;
646                 for ( size_t n = 0; n < c_nSetSize; n +=2 ) {
647                     for ( size_t i = 0; i < c_nInsThreadCount; ++i ) {
648                         if ( !testSet.find( key_type(n, i) ) ) {
649                             if ( ++nErrorCount < 10 ) {
650                                 CPPUNIT_MSG( "key " << n << "-" << i << " is not found!");
651                             }
652                         }
653                     }
654                 }
655                 CPPUNIT_CHECK_EX( nErrorCount == 0, "Totals: " << nErrorCount << " keys is not found");
656             }
657
658             check_before_clear( testSet );
659
660             CPPUNIT_MSG( "  Clear map (single-threaded)..." );
661             cds::OS::Timer    timer;
662             testSet.clear();
663             CPPUNIT_MSG( "   Duration=" << timer.duration() );
664             CPPUNIT_CHECK_EX( testSet.empty(), ((long long) testSet.size()) );
665
666             additional_check( testSet );
667             print_stat( testSet );
668             additional_cleanup( testSet );
669         }
670
671         template <class Set>
672         void test()
673         {
674             CPPUNIT_MSG( "Insert thread count=" << c_nInsThreadCount
675                 << " delete thread count=" << c_nDelThreadCount
676                 << " set size=" << c_nSetSize
677                 );
678
679             for ( size_t nLoadFactor = 1; nLoadFactor <= c_nMaxLoadFactor; nLoadFactor *= 2 ) {
680                 CPPUNIT_MSG( "Load factor=" << nLoadFactor );
681                 do_test<Set>( nLoadFactor );
682                 if ( c_bPrintGCState )
683                     print_gc_state();
684             }
685         }
686
687         template <class Set>
688         void test_extract()
689         {
690             CPPUNIT_MSG( "Insert thread count=" << c_nInsThreadCount
691                 << " delete thread count=" << c_nDelThreadCount
692                 << " extract thread count=" << c_nExtractThreadCount
693                 << " set size=" << c_nSetSize
694                 );
695
696             for ( size_t nLoadFactor = 1; nLoadFactor <= c_nMaxLoadFactor; nLoadFactor *= 2 ) {
697                 CPPUNIT_MSG( "Load factor=" << nLoadFactor );
698                 do_test_extract<Set>( nLoadFactor );
699                 if ( c_bPrintGCState )
700                     print_gc_state();
701             }
702         }
703
704         template <class Set>
705         void test_nolf()
706         {
707             CPPUNIT_MSG( "Insert thread count=" << c_nInsThreadCount
708                 << " delete thread count=" << c_nDelThreadCount
709                 << " set size=" << c_nSetSize
710                 );
711
712             {
713                 Set s;
714                 do_test_with( s );
715                 analyze( s );
716             }
717
718             if ( c_bPrintGCState )
719                 print_gc_state();
720         }
721
722         template <class Set>
723         void test_nolf_extract()
724         {
725             CPPUNIT_MSG( "Insert thread count=" << c_nInsThreadCount
726                 << " delete thread count=" << c_nDelThreadCount
727                 << " extract thread count=" << c_nExtractThreadCount
728                 << " set size=" << c_nSetSize
729                 );
730
731             {
732                 Set s;
733                 do_test_extract_with( s );
734                 analyze( s );
735             }
736
737             if ( c_bPrintGCState )
738                 print_gc_state();
739         }
740
741         void setUpParams( const CppUnitMini::TestCfg& cfg ) {
742             c_nSetSize = cfg.getULong("MapSize", static_cast<unsigned long>(c_nSetSize) );
743             c_nInsThreadCount = cfg.getULong("InsThreadCount", static_cast<unsigned long>(c_nInsThreadCount) );
744             c_nDelThreadCount = cfg.getULong("DelThreadCount", static_cast<unsigned long>(c_nDelThreadCount) );
745             c_nExtractThreadCount = cfg.getULong("ExtractThreadCount", static_cast<unsigned long>(c_nExtractThreadCount) );
746             c_nMaxLoadFactor = cfg.getULong("MaxLoadFactor", static_cast<unsigned long>(c_nMaxLoadFactor) );
747             c_bPrintGCState = cfg.getBool("PrintGCStateFlag", true );
748
749             if ( c_nInsThreadCount == 0 )
750                 c_nInsThreadCount = cds::OS::topology::processor_count();
751             if ( c_nDelThreadCount == 0 && c_nExtractThreadCount == 0 ) {
752                 c_nExtractThreadCount = cds::OS::topology::processor_count() / 2;
753                 c_nDelThreadCount = cds::OS::topology::processor_count() - c_nExtractThreadCount;
754             }
755
756             m_arrData.resize( c_nSetSize );
757             for ( size_t i = 0; i < c_nSetSize; ++i )
758                 m_arrData[i] = i;
759             std::random_shuffle( m_arrData.begin(), m_arrData.end() );
760         }
761
762 #   include "set2/set_defs.h"
763         CDSUNIT_DECLARE_MichaelSet
764         CDSUNIT_DECLARE_SplitList
765         //CDSUNIT_DECLARE_StripedSet
766         //CDSUNIT_DECLARE_RefinableSet
767         CDSUNIT_DECLARE_CuckooSet
768         CDSUNIT_DECLARE_SkipListSet
769         CDSUNIT_DECLARE_EllenBinTreeSet
770         //CDSUNIT_DECLARE_StdSet
771
772         CPPUNIT_TEST_SUITE_( Set_DelOdd, "Map_DelOdd" )
773             CDSUNIT_TEST_MichaelSet
774             CDSUNIT_TEST_SplitList
775             CDSUNIT_TEST_SkipListSet
776             CDSUNIT_TEST_EllenBinTreeSet
777             //CDSUNIT_TEST_StripedSet
778             //CDSUNIT_TEST_RefinableSet
779             CDSUNIT_TEST_CuckooSet
780             //CDSUNIT_TEST_StdSet
781         CPPUNIT_TEST_SUITE_END()
782     };
783
784     CPPUNIT_TEST_SUITE_REGISTRATION( Set_DelOdd );
785 } // namespace set2