3 #include "SortedListTest.h"
4 #include <ptclib/random.h>
7 PCREATE_PROCESS(SortedListTest
);
11 SortedListTest::SortedListTest():PProcess("Reitek S.p.A.", "SortedListTest", 0, 0, BetaCode
, 0)
15 void SortedListTest::Main() {
18 for (i
= 0; i
< 10; i
++) {
22 for (PINDEX j
= i
; j
< i
+ 5; j
++) {
30 DoSomeThing::DoSomeThing(PINDEX _index
)
31 :PThread(1000, AutoDeleteThread
, NormalPriority
, psprintf("DoSomeThing %u", _index
)), index(_index
) {
36 void DoSomeThing::Main() {
38 list
.AllowDeleteObjects();
40 PRandom
rand(PRandom::Number());
44 for (i
= 0; i
< 5000; i
++) {
45 PString
* p
= new PString(rand
.Generate());
48 // cout << GetThreadName() << ": Added " << *p << " element to sorted list" << endl;
49 // coutMutex.Signal();
54 PINDEX remove
= rand
.Generate() % (list
.GetSize() + 1);
55 for (i
= 0; i
< remove
; i
++) {
56 PINDEX index
= rand
.Generate() % list
.GetSize();
58 cout
<< GetThreadName() << ": Removing element " << list
[index
] << " at index position " << index
<< endl
;
61 list
.Remove(&list
[index
]);
66 PINDEX add
= rand
.Generate() % 1000 + 300;
67 for (i
= 0; i
< add
; i
++) {
68 PString
* p
= new PString(rand
.Generate());
70 cout
<< GetThreadName() << ": Adding element " << *p
<< "to sorted list" << endl
;
78 PSafeString::PSafeString(const PString
& _string
):string(_string
) {
82 void PSafeString::PrintOn(ostream
&strm
) const {
87 DoSomeThing2::DoSomeThing2(PINDEX _index
)
88 :PThread(1000, AutoDeleteThread
, NormalPriority
, psprintf("DoSomeThing2 %u", _index
)), index(_index
) {
93 void DoSomeThing2::Main() {
95 PRandom
rand(PRandom::Number());
99 for (i
= 0; i
< 5000; i
++) {
100 PSafeString
* p
= new PSafeString(rand
.Generate());
103 // cout << GetThreadName() << ": Added " << *p << " element to sorted list" << endl;
104 // coutMutex.Signal();
109 PINDEX remove
= rand
.Generate() % (list
.GetSize() + 1);
110 for (i
= 0; i
< remove
; i
++) {
111 PINDEX index
= rand
.Generate() % list
.GetSize();
113 PSafePtr
<PSafeString
> str
= list
.GetWithLock(index
, PSafeReference
);
114 cout
<< GetThreadName() << ": Removing element " << *str
<< " at index position " << index
<< endl
;
116 list
.Remove(&(*str
));
119 PINDEX add
= rand
.Generate() % 1000 + 300;
120 for (i
= 0; i
< add
; i
++) {
121 PSafeString
* p
= new PSafeString(rand
.Generate());
123 cout
<< GetThreadName() << ": Adding element " << *p
<< "to sorted list" << endl
;
128 list
.DeleteObjectsToBeRemoved();