| 1 | #include <iomanip>
|
|---|
| 2 | #include <boost/regex/pending/object_cache.hpp>
|
|---|
| 3 | #include <boost/thread.hpp>
|
|---|
| 4 | #include <string>
|
|---|
| 5 |
|
|---|
| 6 | using namespace std;
|
|---|
| 7 | using namespace boost;
|
|---|
| 8 |
|
|---|
| 9 | // Characters for generating a random string.
|
|---|
| 10 | const char chars[] =
|
|---|
| 11 | "0123456789!@#$%^&*ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|---|
| 12 |
|
|---|
| 13 | // Append random stuff to a string so that we have a random one every time.
|
|---|
| 14 | void appendRandomStuff(string& str)
|
|---|
| 15 | {
|
|---|
| 16 | char* randies = new char[10];
|
|---|
| 17 | for (int i = 0; i < 9; ++i) {
|
|---|
| 18 | randies[i] = chars[rand() % 69];
|
|---|
| 19 | }
|
|---|
| 20 | randies[9] = '\0';
|
|---|
| 21 |
|
|---|
| 22 | str.append(randies);
|
|---|
| 23 |
|
|---|
| 24 | delete[] randies;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | // Loop over object_cache.
|
|---|
| 28 | void worker()
|
|---|
| 29 | {
|
|---|
| 30 | while(true)
|
|---|
| 31 | {
|
|---|
| 32 | string str = string("Hello ");
|
|---|
| 33 | appendRandomStuff(str);
|
|---|
| 34 |
|
|---|
| 35 | object_cache<string, string>::get(str, 5);
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | int main(int argc, char* argv[])
|
|---|
| 40 | {
|
|---|
| 41 | boost::thread threads[10];
|
|---|
| 42 | for (int i = 0; i< 10; i++)
|
|---|
| 43 | {
|
|---|
| 44 | threads[i] = boost::thread(worker);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | // And now we wait.
|
|---|
| 48 | threads[0].join();
|
|---|
| 49 |
|
|---|
| 50 | return 0;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|