Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-threading for C++ #2

Merged
merged 1 commit into from
Oct 3, 2013
Merged

Conversation

t-mat
Copy link
Contributor

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

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
Copy link
Owner

kidoman commented Oct 3, 2013

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

@kidoman
Copy link
Owner

kidoman commented Oct 3, 2013

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

@t-mat
Copy link
Contributor Author

t-mat commented Oct 3, 2013

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
Copy link
Owner

kidoman commented Oct 4, 2013

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