Last change
on this file since 175 was
175,
checked in by scheusso, 16 years ago
|
some advanced testing of threading capability of PacketBuffer in PacketBufferTestExt.cc
|
File size:
1.0 KB
|
Line | |
---|
1 | #include "network/PacketBuffer.h" |
---|
2 | #include "network/PacketBuffer.cc" |
---|
3 | #include <boost/thread/thread.hpp> |
---|
4 | #include <iostream> |
---|
5 | #include <string> |
---|
6 | |
---|
7 | using namespace network; |
---|
8 | |
---|
9 | |
---|
10 | void write(PacketBuffer *test){ |
---|
11 | PacketEnvelope p; |
---|
12 | if(test->isEmpty()) |
---|
13 | std::cout << "empty buffer" << std::endl; |
---|
14 | for(int i=0; i<10; i++){ |
---|
15 | p.data=i*i; |
---|
16 | std::cout << i << ": pushing " << p.data << std::endl; |
---|
17 | test->push(p); |
---|
18 | if(i==5) |
---|
19 | usleep(200000); |
---|
20 | } |
---|
21 | test->setClosed(true); |
---|
22 | return; |
---|
23 | } |
---|
24 | |
---|
25 | void read(PacketBuffer *test){ |
---|
26 | test->print(); |
---|
27 | // exit if the queue is closed and empty |
---|
28 | while(!test->isClosed() || !test->isEmpty()){ |
---|
29 | // only pop if the queue isn't empty |
---|
30 | while(!test->isEmpty()){ |
---|
31 | int i=test->pop().data; |
---|
32 | std::cout << "We popped the value " << i << std::endl; |
---|
33 | } |
---|
34 | } |
---|
35 | return; |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | int main(int argc, char **argv[]){ |
---|
40 | PacketBuffer test = PacketBuffer(); |
---|
41 | boost::thread thrd1(boost::bind(&write, &test)); |
---|
42 | boost::thread thrd2(boost::bind(&read, &test)); |
---|
43 | |
---|
44 | thrd1.join(); |
---|
45 | thrd2.join(); |
---|
46 | |
---|
47 | return 0; |
---|
48 | } |
---|
49 | |
---|
Note: See
TracBrowser
for help on using the repository browser.