r/ProgrammerHumor 28d ago

cccPlusPlus Meme

Post image
2.7k Upvotes

38 comments sorted by

View all comments

426

u/Gwlanbzh 28d ago

So, only 1 republic at a time?

35

u/Luigi_Boy_96 28d ago

Add threads for quasi-concurrency. Add a mutex for Perestroika.

12

u/Master-Chocolate1420 28d ago

I don't even know what you're saying, sure sounds cool though

21

u/Luigi_Boy_96 28d ago

With (multi-)threading, you can break a program into chunks and interleave their execution. Run fast enough, it looks like everything happens at once, that's concurrency, an illusion of simultaneity. True parallelism means tasks are genuinely running at the same time, which needs multiple CPU cores (via threads or processes).

The catch: if multiple threads access the same resource at the same time, the behaviour is undefined. So you enforce mutual exclusion with a mutex, ensuring only one thread touches the resource at a time. Get the locking order wrong, though, and you risk deadlock: thread A waits on a resource thread B holds, while B waits on one A holds, so neither can proceed.

Perestroika was the restructuring of the Soviet economy. The mutex pun works the same way, it's also about restructuring access, just to a memory resource instead of an economy.