Skip to content

Add multi-threading for C++#2

Merged
kidoman merged 1 commit into
kidoman:masterfrom
t-mat:cpp-multithread
Oct 3, 2013
Merged

Add multi-threading for C++#2
kidoman merged 1 commit into
kidoman:masterfrom
t-mat:cpp-multithread

Conversation

@t-mat

@t-mat t-mat commented Oct 3, 2013

Copy link
Copy Markdown
Contributor

If you use g++, please add -std=c++11 -pthread to your command line option.

g++ -std=c++11 -pthread -O3 rays.cpp
./a.out > rays.ppm

kidoman added a commit that referenced this pull request Oct 3, 2013
add multi-threading for c++
@kidoman
kidoman merged commit 570c750 into kidoman:master Oct 3, 2013
@kidoman

kidoman commented Oct 3, 2013

Copy link
Copy Markdown
Owner

Thanks for the PR... nice to learn this feature of C++ :)

@kidoman

kidoman commented Oct 3, 2013

Copy link
Copy Markdown
Owner

Is it possible to have this use 1 vs N cores programmatically?

@t-mat

t-mat commented Oct 3, 2013

Copy link
Copy Markdown
Contributor Author

Yes, and no.

1 thread : yes

You can achieve 'single thread mode' by the following change :

-   wg.push_back(std::async(std::launch::async, [&, y](unsigned int seed) {
+   wg.push_back(std::async(std::launch::deferred, [&, y](unsigned int seed) {

see also

N threads : no

But for now there is no convenient and standard way to limit the maximum amount of threads.

You can achive the feature by thread pool or std::condition_variable, but I think it is too much complicated for this kind of simple project.

@kidoman

kidoman commented Oct 4, 2013

Copy link
Copy Markdown
Owner

Oh alright

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants