r/Cplusplus • u/Select_Transition287 • 1d ago
Discussion Exp. C++ Dev - Getting started with multithreading ?
/r/cscareerquestions/comments/1y212pn/exp_c_dev_getting_started_with_multithreading/
3
Upvotes
1
u/Middlewarian 1d ago
I try to minimize the use of multi-threading io_uring for Systems Engineers : r/programming
You can do a lot with multiple instances of single threaded processes. I heard Linus Torvalds wasn't much of a fan of databases.
1
u/HotComplex4744 1d ago
Sorry. My English very poor :((( translate next text if u want...
1
u/Discordbothost 1d ago
A slow file import in a desktop app is a good exercise. Move it to one worker, post the result back to the UI thread, then try closing the window mid-import. That last case is where ownership and cancellation get interesting.
1
u/DubiousLogik 1d ago
how serious are you about working in back end servers? Many of those are written in c# or java, which is an easy move given your background. where i just worked (big tech co with >100k ppl) most servers were c#, unless they did a really specialized job and needed that low level perf optimization. And those in the latter category were moving to Rust. folks really don't like chasing memory leaks on server farms in someone else's code. Node was another server that I saw often, and folks optimized for lots of lightweight single threaded instances.
wrt databases - that's a whole topic on its own, esp for scale out in a cloud environment. partitioning, failover, conflict resolution etc are all big topics. Not to dissuade you - the tech challenges are fascinating, but it is a different skillset. I think the q is what do you need a db for - are you thinking of 'full stack' development, e.g. for ecommerce/banking/whatever? Or more reporting/BI kind of things? (I did a lot of data pipelines for the latter, diff than transactional stuff)
Fwiw I saw a lot of folks come from c++ into c#, t-sql, etc and they all did really well. It's like c++ is a really tough boot camp and most other langs are fast to learn after that. I think one q for you is do you want to stay in c++ exclusively, or do u want to learn whatever lang ppl are using for the task at hand.
1
u/EmperorOfCanada 1d ago
Threading is something which most programmers are extremely weak at.
Threading goes far beyond the simple concept of threads on a processor. The philosophy, the art, and the science of threading stretch right out into distributed systems, including where it can get very fuzzy.
For example. If a user has a form open on a browser, that is kind of a thread. It is sitting there waiting for their input, and then it shoots data back into the main system, where it has to interact with other "threads".
The two places where I learned the most about threads were distributed systems and embedded. Both of them push all you know about message passing, interrupts, and every pattern you can conceive of. Embedded is a real nasty one as you often are dealing with real time data processing. You have pulses coming in and out, and those need to be processed without any delay, and sent exactly when they need to be sent. Yet, on a typical microprocessor, you only have one core. Thus, you need to do preemptive multi-tasking with some other tricks to keep things "real-time"
One place where you get an excellent "feel" for threads are games. If you have a thread for the GUI, a thread for networking, a thread for music, and a thread for sound effects, and heck, some other threads just to keep it amusing like ones for enemy AI; then you literally see and hear any thread glitches.
So, I would recommend games. You can start small. Multi-player pong. It doesn't have to be an FPS, as something like pong means that you are handling pretty much every single bit of data moving around in your code, and you aren't handing it over to some other thread optimized tool.