c:c_threads:multi_threading
Differences
This shows you the differences between two versions of the page.
c:c_threads:multi_threading [2021/04/28 09:28] – created peter | c:c_threads:multi_threading [2021/06/08 09:38] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== C - C++ Threads - Multi threading ====== | ||
- | |||
- | ===== start_thread.hpp ===== | ||
- | |||
- | <code cpp> | ||
- | #pragma once | ||
- | |||
- | #include < | ||
- | |||
- | std:: | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== start_thread.cpp ===== | ||
- | |||
- | <code cpp> | ||
- | #include " | ||
- | #include < | ||
- | #include < | ||
- | |||
- | class SampleThreadClass | ||
- | { | ||
- | public: | ||
- | void threadFunction(int inputVal) | ||
- | { | ||
- | while (running) | ||
- | { | ||
- | result += inputVal; | ||
- | } | ||
- | } | ||
- | |||
- | |||
- | std:: | ||
- | int64_t result{0}; | ||
- | }; | ||
- | |||
- | |||
- | |||
- | int64_t startAndStopThread(int runningMilliseconds, | ||
- | { | ||
- | SampleThreadClass sampleThreadClass; | ||
- | |||
- | // Start thread. | ||
- | std::thread t = std:: | ||
- | |||
- | |||
- | // Wait. | ||
- | std:: | ||
- | |||
- | |||
- | // Stop thread. | ||
- | sampleThreadClass.running = false; | ||
- | t.join(); | ||
- | |||
- | |||
- | return sampleThreadClass.result; | ||
- | } | ||
- | </ | ||
c/c_threads/multi_threading.1619602116.txt.gz · Last modified: 2021/04/28 09:28 by peter