Ticket #4415: SharedPtrCrushTest.cpp

File SharedPtrCrushTest.cpp, 985 bytes (added by Takenori Sato <takenori.sato@…>, 12 years ago)
Line 
1#include <boost/shared_ptr.hpp>
2#include <iostream>
3
4class IntSLLNode {
5
6private:
7 int index;
8 boost::shared_ptr<IntSLLNode> next;
9
10 IntSLLNode(int ix){
11 index = ix;
12 }
13
14public:
15 int hasNext(){return next != 0;}
16 boost::shared_ptr<IntSLLNode>& moveNext(){return next;}
17 int getIndex(){return index;}
18 friend class IntSLList;
19};
20
21class IntSLList {
22private:
23 boost::shared_ptr<IntSLLNode> head, tail;
24public:
25 ~IntSLList(){/* do nothing */};
26
27 void addNode(int index){
28
29 boost::shared_ptr<IntSLLNode> n(new IntSLLNode(index));
30 if(head == 0){
31 head = tail =n;
32 }
33 else
34 {
35 tail->next = n;
36 tail = n;
37 }
38
39 }
40
41 boost::shared_ptr<IntSLLNode>& getHeadNode(){return head;}
42};
43
44int main(){
45 IntSLList list;
46 // the number to reproduce crush may vary, but seems to be stable
47 // On my Core2Duo box, it is around 65000
48 // Here I dare to use a value large enough
49 for(int i=0; i<1000000; i++){
50 list.addNode(i);
51 }
52 // crush at destruction
53 std::cout << "CRUSH?" << std::endl;
54}