How many threads does it take to make them a bad choice?

前端 未结 15 2576
猫巷女王i
猫巷女王i 2021-02-07 21:46

I have to write a not-so-large program in C++, using boost::thread.

The problem at hand, is to process a large (maybe thousands or tens of thousands. Hundreds and millon

15条回答
  •  情话喂你
    2021-02-07 22:03

    You said the files are all in one directory. Does that mean they are all on one physical drive?

    If that is so, and assuming they are not already cached, then your job will be to keep the single read head busy, and no amount of threading will help it. In fact, if it has to hop between tracks due to parallelism, you could slow it down.

    On the other hand, if the computation part takes significant time, causing the read head to have to wait, then it might make sense to have >1 thread.

    Often, using threads for performance is missing the point unless it lets you get parallel pieces of hardware working at the same time.

    More often, the value of threads is in, for example, keeping track of multiple simultaneous conversations, like if you have multiple users, where each thread can wait for its own Johny or Suzy and not get confused.

提交回复
热议问题