Talk:cpp/thread/unique lock/unique lock

Regarding the example

This example is sufficiently complicated (perhaps) to be mainly be useful to someone who does not need an example. Note that the page is about the constructor and the example is 2 screen sizes (on my monitor) in length. Where the constructor actually occurs it is further obfuscated by a using clause.

GuardLock lock_a(a.mutex_, std::defer_lock); // obscures the thing being demonstrated

Why do that? (There is another using clause for the mutex which does not contribute to the code) The example includes a few ostream member overrides and, really, that vector of threads where emplace_back is called with update is nice but was it done just to have a tight loop calling join on each?

Don't get me wrong, this is nice code and a clever way to display some Fibonacci numbers but it does not illuminate the unique_lock constructor.

I can't find it now but a while back I commented on an example that I thought was too terse. The reply I got was something like "examples are the minimum to show what is needed to compile". I'm advocating for something in the middle. Arbalest (talk) 12:42, 8 February 2014 (PST)


 * I am commenting rather than changing the example since I have been a rather inactive member of the community and don't want to step on any toes. Arbalest (talk) 12:42, 8 February 2014 (PST)


 * I agree, it's a whole lot of code to show a call to just one of the constructors (the defer_lock_t overload). If anything, it's an example for std (which, incidentally, could use an example that applies it to unique_locks rather than raw mutexes). --Cubbi (talk) 13:07, 8 February 2014 (PST)