π§΅
STUDENT NOTES Β· C & C++ WEEK 8 OF 8
Many Hands, One Program π§΅
Servers, games and robots do many things AT ONCE. The final superpower: threads β and the locks that keep them honest.
1std::thread β hiring a second worker
βοΈ
Chip: A thread is another worker inside your program, running a function AT THE SAME TIME as main. join() means "wait for the worker to finish before moving on".
2The race condition π
π
Bugly: TWO workers writing the same variable with no rules? The results interleave randomly. Works in testing, explodes at the demo. My FINAL FORM. Hehehe!
3mutex β one worker at a time
π¦
Professor Hoot: A mutex is a talking stick: only the thread holding it may touch the shared data. Everyone else queues politely. Race condition β solved.
4Ship your capstone π
π€
Bittu: Compile with g++, push to GitHub with a README, add the link to your resume. A finished C++ project makes core-company interviewers sit up straight.
5Quick quiz! π§
t.join() does what?
π‘ Skip join and main() may exit while the worker is mid-job. join = wait for your teammate.
Two threads write the same variable with no mutex. This isβ¦
π‘ Unsynchronized shared writes interleave randomly. The mutex is the cure.
6Your final mission π
Mission 1: Spawn a thread that prints 1β5 while main prints AβE. Watch them interleave!
Mission 2: Finish your capstone, test it like a villain (Week 3 energy), write the README.
Mission 3: Push it to GitHub, add the link to your resume β and plan next month's build. The streak starts now. π₯
ALL 8 WEEKS COMPLETE! ππ
From printf("Hello") to multithreaded C++ on GitHub. Finish the capstone, claim the certificate β and keep building.
Back to the Video Platform β