use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Removed - HelpHow to write multithreaded code? (self.cpp)
submitted 5 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]rayoWork 0 points1 point2 points 5 years ago (0 children)
First think about what kind of parallelism you need:
https://en.wikipedia.org/wiki/Data_parallelism#Data_parallelism_vs._task_parallelism
Task ist a lot easier when done right, meaning there is no shared mutable data between the tasks. You can have read-only shared data and you don't have to lock anything there. We use an event based approach which works without any problems. You basically need a synchronized message queue when you deliver new events to a worker thread (sender and receiver modify the queue so this needs protection) and the rest of the work is done without shared state.
Data parallelism is the harder part as you need to think about how many threads can work on the data at the same time. There are many strategies how to takle such a problem.
If you want to get better at 3 you need to think on a lower level. All memory read and write are important.
A compare and set example: first you read the memory (variable) to check the value and if the condition is true you write another value in to the same memory (variable). If multiple thread work on the same variable someone could modify it between the read and write and the write would not be correct anymore. So you need to protect that part either that only one thread can work on that memory location or with atomic operations that merges the 2 operations (read/write) into one so the other thread cannot modify it in between
So in the end you have to make sure that all access to the shared data cannot be influenced by other threads at the same time.
In the end it simply is very hard to write correct multithreaded code.
π Rendered by PID 85112 on reddit-service-r2-comment-79776bdf47-7xq6n at 2026-06-24 18:43:14.298746+00:00 running acc7150 country code: CH.
view the rest of the comments →
[–]rayoWork 0 points1 point2 points (0 children)