Giter Club home page Giter Club logo

cpp-concurrency-in-action-2ed's Introduction

cpp-concurrency-in-action-2ed's People

Contributors

downdemo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpp-concurrency-in-action-2ed's Issues

关于线程池这一章的问题

“往线程池添加任务会增加任务队列的竞争,lock-free 队列可以避免这点但存在乒乓缓存的问题。为此需要把任务队列拆分为线程独立的本地队列和全局队列,当线程队列无任务时就去全局队列取任务”

在这一小节中,submit函数中的local_queue永远是nullptr,原因如下:
local_queue指针在worker_thread中赋值,woker_thread运行在子线程,而submit函数是在main线程中调用的,二者不是在同一线程,所以二者的local_queue根本不是同一个。

所以这段代码无法达到想要的目的。

在“8.1.2 以递归方式划分数据”中的 parallel_quick_sort不能正常运行

下面是运行代码:
int main(){
std::list data = {5,1,2,9,100,8};
auto sorted_data = parallel_quick_sort(data);
for(auto it: sorted_data ){
printf("%d", it);
}
}
出错信息:
terminate called after throwing an instance of 'EmptyStack'
what(): empty stack!
[1] + Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-m25ftpou.0wk" 1>"/tmp/Microsoft-MIEngine-Out-xpupxdid.5th"

some questions.

你好,我最近也在看这本书,我有一些疑问想跟你探讨一下不知你是否方便?

  1. P20 ,The act of calling join() also cleans up any storage associated with the thread, so the std::thread object is no longer associated with the now-finished thread; it isn’t associated with any thread. 这句话我没太懂?

  2. P22 The copy constructor and copy-assignment operators are marked =delete to ensure
    that they’re not automatically provided by the compiler. Copying or assigning such an
    object would be dangerous, because it might then outlive the scope of the thread it was
    joining. By declaring them as deleted, any attempt to copy a thread_guard object will
    generate a compilation error. 如果不将copy-assignment 定为 deleted的话,为什么是危险的呀?能否举一个例子?

应该是C++11规定 static local variable 的初始化是线程安全的和 copy assignment operator 漏写了字符 =

downdemo1

文件位置: content/02 线程间共享数据.md
https://github.com/downdemo/Cpp-Concurrency-in-Action-2ed/blob/cbd88caed525fffb736b4fe2fd3aa61a2d1f3bb2/content/02%20%E7%BA%BF%E7%A8%8B%E9%97%B4%E5%85%B1%E4%BA%AB%E6%95%B0%E6%8D%AE.md

Issue1

《C++ Concurrency in Action》Second Edition,Chapter 3.3.1 节最后部分关于 static变量 初始化的描述,仅指的是 static local variable 的初始化自 C++11 起是线程安全的,对于 static non-local variable 是未提及的,即对于具有静态存储期的非局部变量,如 global variable 和类的 static data member ,它们的初始化会作为程序启动的一部分在 main 函数的执行之前进行:简单的类型会在编译期进行初始化,如 constexpr 类型,复杂的类型则需要在运行期初始化,如 复杂的类对象(初始化时需要调用构造函数)。在程序结束时它们才会被销毁。因为 static non-local variable 的初始化会作为程序启动的一部分在 main 函数的执行之前进行,所以其初始化不存在多个线程竞争初始化的问题,但是却存在异常安全和 initialization order 的问题。详见 Static local variable and Global variable

即文中应该写为: “C++11规定static局部变量的初始化……”

Issue2

class A 的 copy assignment operator 漏写了字符 = ,即应该是: A& operator=(const A&) = delete;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.