Article View: pl.comp.lang.c
Article #309611Szukam przykładu thread_pool
From: Borneq
Date: Sat, 13 Jan 2018 13:09
Date: Sat, 13 Jan 2018 13:09
23 lines
1717 bytes
1717 bytes
Jest tylko https://exceptionshub.com/thread-pooling-in-c11.html
i identyczny na Stack Overflow, czyli
#include <ctpl.h> // or <ctpl_stl.h> if ou do not have Boost library
int main (int argc, char *argv[]) {
ctpl::thread_pool p(2 /* two threads in the pool */);
int arr[4] = {0};
std::vector<std::future<void>> results(4);
for (int i = 0; i < 8; ++i) { // for 8 iterations,
for (int j = 0; j < 4; ++j) {
results[j] = p.push([&arr, j](int){ arr[j] +=2; });
}
for (int j = 0; j < 4; ++j) {
results[j].get();
}
arr[4] = *std::min_element(arr, arr + 4);
}
}
(gdzie ostatni wiersz nie będący klamrą poprawiłem dając gwiazdkę)
Szukam sensownym przykładów kodu w C++, tak by działanie było podobne do
tego opisu w Wikipedii:
https://en.wikipedia.org/wiki/Thread_pool
Technical Details
Message-ID:
<p3d0dt$k1h$1@node2.news.atman.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail From: Borneq <borneq@antyspam.hidden.pl> Newsgroups: pl.comp.lang.c Subject: Szukam przykładu thread_pool Date: Sat, 13 Jan 2018 14:09:17 +0100 Organization: ATMAN - ATM S.A. Lines: 23 Message-ID: <p3d0dt$k1h$1@node2.news.atman.pl> NNTP-Posting-Host: public-gprs351624.centertel.pl Mime-Version: 1.0 X-Trace: node2.news.atman.pl 1515848957 20529 37.47.4.201 (13 Jan 2018 13:09:17 GMT) X-Complaints-To: usenet@atman.pl NNTP-Posting-Date: Sat, 13 Jan 2018 13:09:17 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 X-Mozilla-News-Host: news://news.atman.pl:119 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit