Multithreading to perform a single task in C ++

Suppose I have this function big_task()that I can share between threads for speed.

How to solve this problem using multithreading, you need to call _beginthread()functions for each task, and then wait for all threads to complete?

How do I know that it will be effective and really help minimize time big_task()?

I also heard that multithreading efficiency depends on the platform and equipment of the client. This means that I also need to request at the beginning of my program.?

One more question: when coding in Windows it is better to use CreateThread(), but not _beginthread()? I write cross-platform applications, but if CreateThread()more efficient than I could set aside my code for use on Windows.

+4
source share
2 answers

Hope this helps you get started.

To achieve acceleration in a single-threaded approach, you need a multi-core processor. In a single-core processor, an additional thread will not increase the speed of calculations, but it can help to make other functions smoother (for example, GUI) at the same time during intensive work with the processor.

, " " , .

:

  • . "".
  • , ( ).
  • . .

    1. "" "". "" , .
    2. "".
    3. (4)

. , , , Ctrl-C. "" ( ) .

.

, , , . , . mutex (. boost:: mutex).

. (FIFO) . , , .

boost:: thread.

: boost:: thread_group

+2

, _beginthread() , ?

, , .

, big_task()?

. -, , .

, . , .?

, , , , , PPL ( ), TBB, OpenMP-, .

: Windows CreateThread(), _beginthread()? - , CreateThread() , Windows.

-, std:: thread boost .

+5

Source: https://habr.com/ru/post/1616495/


All Articles