Skip to content

Commit 2fae275

Browse files
committed
Add some usage example code in comments.
1 parent 29b2996 commit 2fae275

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

Concurrency/ConcurrentWrapper2/Concurrent.h

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
/// on C++ concurrency by Herb Sutter:
55
/// http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Herb-Sutter-Concurrency-and-Parallelism
66
///
7-
/// Tweaked to compile with g++ 4.7.2.
7+
/// This is an extension of the concurrent wrapper presented in this blog:
8+
/// http://juanchopanzacpp.wordpress.com/2013/03/01/concurrent-object-wrapper-c11/
9+
///
10+
/// Currently does not compile on gcc 4.7 or 4.8 due to a compiler bug related
11+
/// to decltype of member variables used in a trailing return type.
12+
/// This is expected to be fixed in GCC 4.8.1.
813
///
914
/// Wraps a shared resource such that callers can request operations on the resource asynchronously.
1015
/// Each request is treated as an atomic transaction, and the caller side is not blocked.
@@ -15,20 +20,27 @@
1520
/// Example useage:
1621
///
1722
/// @code
18-
/// Concurrent<std::string> cs;
23+
/// Concurrent<std::vector<int>> cv;
24+
///
25+
/// //1: Resize the vector, fill with sequence
26+
/// auto f1 = cv([](std::vector<int>& v)->size_t{ v.resize(10);
27+
/// std::iota(v.begin(), v.end(), 0);
28+
/// return v.size();
29+
/// });
1930
///
20-
/// //Thread 1: just print the string
21-
/// cs([](const std::string& s){ std::cout << s;});
31+
/// //2. Calculate the sum of elements
32+
/// auto f2 = cv([](const std::vector<int>& v){ return std::accumulate(v.begin(), v.end(), 0);});
2233
///
23-
/// // Thread 2:
24-
/// void foo(std::string& s);
25-
/// void bar(std::string& s);
34+
/// //3: Call some user defined functions
35+
/// int foo(std::vector<int>& v);
36+
/// void bar(std::vector<int>& v);
2637
/// // run bar, then foo on the shared resource
27-
/// cs([] (std::string& s) { bar(s); foo(s);});
28-
///
29-
/// // Thread 3: make string uppercase
30-
/// cs([](std::string& s){ for (auto& c : s) c = static_cast<char>(std::toupper(c));)} );
38+
/// auto f3 = cs([] (std::vector<int>& v)->int { bar(v);
39+
/// return foo(v);
40+
/// });
3141
///
42+
/// //4 get the results when needed
43+
/// std::cout << f1.get() << " " << f2.get() " " << f3.get() << std::endl;
3244
///
3345

3446
#include <functional>

0 commit comments

Comments
 (0)