Philosophers: multitasking in programming might even be harder than in real-life
A code project in which I learned how it feels to deal with threads in programming.
I'm terrible at multitasking. That's because when doing two things at the same time, that's two times more things about everything that can change. What made me feel a little bit better though, is that it apparently isn't any different for computers.
This has to do with the fact that every action of what a computer can do are always made up of tiny steps. These steps should always happen in the right order without interruption. And if there were to say two actions that a computer should do at the same time, then the steps for those two actions are mixed up with each other, unless you prevent that from happening. Traditionally, this is the programmer's job.
The 42 project Philosophers introduces you to this concept. You learn what 'threads' are and how you can prevent them from getting knotted together and messing up your computer, by using so-called 'mutexes' that help you do all the steps in the right order.
What I learned
This project gave a better Fingerspitzengefühl for how the quality of the machine and the quality of the code influence the running speed. Working with so many threads really gets very different performance on different machines and with or without optimizations. Comparable how push_swap made me realize how quick a computer can execute tasks and make calculations after each other, this project gave me a greater understanding of how many threads computers can run alongside each other and what possibilities that gives.
Curious? Have a look yourself at the code!
![](https://gitlab.com/assets/twitter_card-570ddb06edf56a2312253c5872489847a0f385112ddbcd71ccfa1570febab5d2.jpg)
To understand what the project is about, read the subject: