#Threading
Explore tagged Tumblr posts
aurock · 3 months ago
Text
Let's Talk Locks (and Chopsticks!): Diving into the Dining Philosophers Problem
Heyyyy,
So, I'm super excited to start diving into some classic computer science concepts here, especially those that pop up in the world of Linux and concurrent programming. And what better place to start than with the fascinating (and sometimes frustrating!) Dining Philosophers Problem (I learned it about two days ago so please be patient :P).
Tumblr media
Think about it: a group of philosophers are sitting around a circular table. In front of each philosopher is a bowl of delicious spaghetti. To eat (somehow) a philosopher needs two chopsticks – one to their left and one to their right. However, there's only one chopstick between each pair of philosophers.
The philosophers have a simple life cycle: they think, they get hungry, they try to pick up their chopsticks, they eat, and then they put the chopsticks down and go back to thinking.
The tricky part arises when multiple philosophers get hungry at the same time. If everyone picks up their left chopstick simultaneously, no one can pick up their right chopstick! They all end up waiting indefinitely, holding one chopstick and starving. This, my friends, is a classic example of a deadlock (and I'm not talking about Valorant's agent ;) ).
Now, why is this relevant to Linux and programming?
Well, the Dining Philosophers Problem is a great analogy for common issues we face when dealing with concurrent processes or threads that need to access shared resources (like those chopsticks!). Chopsticks represent shared resources: Think of these as locks, mutexes, semaphores, or any other mechanism used to control access to critical sections of code (I'm going to talk about those in another posts). Philosophers represent processes or threads: These are the independent units of execution trying to use the shared resources.
The act of picking up chopsticks represents acquiring locks: A process needs to acquire the necessary locks before it can proceed with its task (eating). Deadlock in the problem mirrors deadlock in programs: Just like the philosophers can get stuck waiting for each other's chopsticks, threads can get stuck waiting for locks held by other threads, leading to a program freeze (don't try it at home).
There are several interesting ways to approach solving the Dining Philosophers Problem (and preventing deadlocks in our programs!). Some common strategies include: Introducing a resource hierarchy: Making philosophers pick up chopsticks in a specific order. Allowing a philosopher to pick up both chopsticks only if both are available. Introducing a central coordinator. Limiting the number of philosophers trying to eat at the same time.
What are your initial thoughts on the Dining Philosophers Problem?
Have you encountered similar deadlock situations in your own programming projects? Let me know!
I'm planning on diving deeper into some of the solutions in future posts ;)
6 notes · View notes
5leggedlamb · 1 year ago
Text
I tried a more complicated pattern and uuuuuh
Tumblr media
It looks like something alright...
But that's OK. Things you craft don't have to be perfect, especially if you're doing it for the first time. Be proud of trying something new.
3 notes · View notes
pragretti · 20 days ago
Text
🫐
Tumblr media Tumblr media Tumblr media Tumblr media
Kirsten Chursinoff
A selection of berry-themed textile art. Free-motion machine quilting and hand embroidery, using some quilting and applique techniques.
16K notes · View notes
edsrosetattoo · 8 months ago
Text
Tumblr media
This is the best idea in the history of film.
166K notes · View notes
nudityandnerdery · 2 days ago
Text
Tumblr media
44K notes · View notes
its-funnytwittertweets · 1 month ago
Text
Tumblr media
42K notes · View notes
opera-ghost · 2 months ago
Text
Tumblr media Tumblr media
53K notes · View notes
tweetingukpolitics · 5 months ago
Text
Tumblr media
47K notes · View notes
victusinveritas · 13 days ago
Text
Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media
Nice people make the best Nazis. Be mean, be tough, have a fascist tooth/skull collection.
28K notes · View notes
soracities · 1 year ago
Text
Tumblr media
"Absolutely no one comes to save us but us."
Ismatu Gwendolyn, "you've been traumatized into hating reading (and it makes you easier to oppress)", from Threadings, on Substack [ID'd]
200K notes · View notes
ashortstoryaboutlove · 1 month ago
Text
Tumblr media
And the best reply:
Tumblr media
[Source 1] [Source 2]
Edited to add:
Tumblr media
[Source]
31K notes · View notes
wiisagi-maiingan · 5 months ago
Text
Hey, if you do crafts (especially things like crochet, knitting, embroidery, etc), make sure to look up how to identify when a listing is AI generated. You do NOT want to waste money on an incredible looking kit or pattern that is physically impossible to make, especially if you're on sites like etsy hoping to support an actual artist.
28K notes · View notes
5leggedlamb · 1 year ago
Text
Ok so I tried it with thicker thread and omg this thing looks as if it's going to last me 5 generations what the hell
Tumblr media
3 notes · View notes
teathattast · 18 days ago
Text
Tumblr media
19K notes · View notes
bibbysstuff · 2 months ago
Text
Mc in Lingeries, Li addition
Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media
14K notes · View notes