博文

目前显示的是 二月, 2018的博文

ch3 sharing data between threads

3.1 problems with sharing data between threads 3.1.1 the definition race condition which is problematic 3.1.2 avoide problematic race conditions 1) protection 2) lock-free 3) transaction 3.2 protecting shared data with mutexes 3.2.1 using mutex std::mutex std::lock_guard 3.2.2 structuring code for protecting shared data mutex and data within same class 3.2.3 race condition inherent in the interfaces the exception free stack: split the top and pop, because if pop return the value, the poped element's copy constructor could throw exception. but the split cause interface problematic race conditions.  1) pass by reference which avoid the copy constructor,  2) only support exception free copy constructor or move consturctor.  3) return the pointer rather than the value which eliminating the copy constructor.(return std::shared_ptr) question is: std::make_shared<T>(?) what is the parameter type??? i think the only thing would be std::make_shared<...

ch2 managing threads

2.2. Passing argument to the std::thread 1. first the implict convertion is execute on which thread. the thread test demo shows that the implict argument convertion is in the target thread. 2. what is c++ function object? why it could represent a function? a class with overloaded function call operator. because it could use itself to call the function. 3.  c/c++ expression parse? Start reading the declaration from the innermost parentheses, go right, and then go left. When you encounter parentheses, the direction should be reversed. Once everything in the parentheses has been parsed, jump out of it. Continue till the whole declaration has been parsed. One small change to the right-left rule: When you start reading the declaration for the first time, you have to start from the identifier, and not the innermost parentheses. https://www.codeproject.com/Articles/7042/How-to-interpret-complex-C-C-declarations 4. the functor std::thread my_thread(background_task()) ...